Code Monkey home page Code Monkey logo

jpa-with-json-field-example's Introduction

Creating Java JPA Entities with a JSON Field

This is the code sample to accompany the blog post: Creating Java JPA entities with a JSON field.

This repository illustrates the usage of an JSON field within a JPA entity. The point is to show how you can use JPA entities and still have JSON persisted in your underlying PostgreSQL database.

Steps to see everything in action:

  1. Ensure that you have created the PostgreSQL DB, and the schema (see src/main/resources/db for the schema scripts).
  2. Update the src/main/resources/application.properties file to have the correct values for your data source.
  3. Run the bootRun Gradle task to launch the Spring Boot application.
  4. Make a POST request to create a new Person
    # Create a new person
    curl -X POST -H "Content-Type:application/json" -d '{
        "firstName": "John",
        "surname": "Smith",
        "address": {
            "doorNumber": 2,
            "roadName": "London Road",
            "postalCode": "EC34AWE"
        }
    }' http://localhost:8080/people
  5. Check the DB - you will have stored JSON!
  6. Make a PUT request to update the Person
    # Update an existing person
    curl -X PUT -H "Content-Type:application/json" -d '{
        "firstName": "John",
        "surname": "Smith",
        "address": {
            "doorNumber": 35,
            "roadName": "New York Road",
            "postalCode": "12345"
        }
    }' http://localhost:8080/people/1
  7. Check the DB - your JSON would have been updated!

Enjoy!

Also - if you have not yet already: check out the LigerLearn website and YouTube channel.

jpa-with-json-field-example's People

Contributors

ligerlearn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.