jax rs - Use JSON.stringify and JSON.parse in resteasy -
i need use json.stringify , json.parse in java class contains resteasy services exchange information jquery script. library should import java class or should ?, because in script let me default. thank much.
so understanding want able serialize , deserialize json , java object, that's json.stringify
, json.parse
javascript.
to able handle that, need messagebodyreader
, messagebodywriter
handle conversion. resteasy has providers available part of framework. need add module.
hopefully using maven, if not see post. maven should have either 1 of these dependencies
<dependency> <groupid>org.jboss.resteasy</groupid> <artifactid>resteasy-jackson-provider</artifactid> <version>${resteasy.version}</version> </dependency> <dependency> <groupid>org.jboss.resteasy</groupid> <artifactid>resteasy-jackson2-provider</artifactid> <version>${resteasy.version}</version> </dependency>
the difference in jackson flavor used 1.x or 2.x
once have provider on classpath, should auto configured. need use pojo ad conversion done e.g
@get @produces("application/json") public response getmypojo() { mypojo pojo = new mypojo(); return response.ok(pojo).build(); } @post @consumes("application/json") public response createmypojo( mypojo pojo ) { // pojo }
Comments
Post a Comment