Json direct to Java class?

Hi,

I've been using XContentBuilder within the Java API to index
documents. Is there a corresponding way to populate objects with JSON
data? E.g. in Gson you can say

BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class);

Thanks

So you can use gson, or Jackson which is embedded in ES or your own version of Jackson.

XContentBuilder is nice when you don't need to serialize/deserialize beans.

HTH
David.

Le 3 févr. 2012 à 17:40, Ben Rometsch ben@solidstategroup.com a écrit :

Hi,

I've been using XContentBuilder within the Java API to index
documents. Is there a corresponding way to populate objects with JSON
data? E.g. in Gson you can say

BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class);

Thanks

You can use Jackson to serialize java to json and vice-versa.

The json will have to be converted to byte array for better performance.

Feel free to read

You can browse the code source (focus on SearchEngineImpl) for a working
example.

Cheers,

Louis.

2012/2/3 Ben Rometsch ben@solidstategroup.com

Hi,

I've been using XContentBuilder within the Java API to index
documents. Is there a corresponding way to populate objects with JSON
data? E.g. in Gson you can say

BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class);

Thanks

--
Cordialement/Regards,

Louis GUEYE
linkedin http://fr.linkedin.com/in/louisgueye |
bloghttp://deepintojee.wordpress.com/|
twitter http://twitter.com/#!/lgueye