Accessing Baratine's JSON serializer/deserializer

11 views
Skip to first unread message

ty...@foreflight.com

unread,
Oct 2, 2016, 10:28:17 AM10/2/16
to Baratine
Is there a way to get access to Baratine's JSON serializer / serialization service for use in a means other than request.ok()? E.g. via injection?

-tyson

Nam Nguyen

unread,
Oct 3, 2016, 6:06:42 AM10/3/16
to barat...@googlegroups.com
On 10/2/16 7:28 AM, ty...@foreflight.com wrote:
> Is there a way to get access to Baratine's JSON serializer / serialization service for use in a means other than request.ok()? E.g. via injection?
>
> -tyson

I've updated the docs on using the built-in JSON library:

file:///Users/nam/caucho/git/baratine-doc/doc/build/html/manual/json.html


Example:

@Inject
private JsonEngine jsonEngine;

// or getting it programmatically
JsonEngine jsonEngine =
Services.current().injector().instance(JsonEngine.class);

// or creating it directly
JsonEngine jsonEngine = new JsonEngineDefault();

// writer usage
JsonWriter writer = jsonEngine.newWriter();
jsonWriter.init(writer);
jsonWriter.write(value);
jsonWriter.flush();

// reader usage
JsonReader reader = jsonEngine.newReader();
reader.init(reader);
MyObject my = reader.readObject(MyObject.class);


-- Nam
Reply all
Reply to author
Forward
0 new messages