eugene-kamenev / orientdb-spring-boot-example

OrientDB usage example with spring boot ang groovy
5 stars 3 forks source link

Short example of JSON PUT ACTION #1

Open zotona opened 8 years ago

zotona commented 8 years ago

Hi! Very interesting project! Could you provide some small example to persist json string to orient?

eugene-kamenev commented 8 years ago

@zotona Ok i will provide two examples:

  1. spring way
@RequestMapping(method = RequestMethod.PUT)
def putPerson(Person p) {
    graphFactory.withTransaction {
           p.save()
    }
}

In the above case you must register jackson object mapper for your object, but i didnt tested how it works with this lib.

  1. groovy way
@RequestMapping(method = RequestMethod.PUT)
def putPerson(String person) {
    def slurper = new  groovy.json.JsonSlurper()
    graphFactory.withTransaction {
           new Person((Map) slurper.parseText(person)).save()
    }
}
eugene-kamenev commented 8 years ago

You can give a star if you like this project. Thank you.

zotona commented 8 years ago

Thanks for the answer. 1st example doesnt work. something wrong this objectmapping in jackson http2objecthandler (could not instantiate Person class) 2nd - worked.