Java Class for obtaining corresponding Gson json object -
i have json object following representation :
{ text : "ed o'kelley man shot man shot jesse james.", entities : [ ['t1', 'person', [[0, 11]]], ['t2', 'person', [[20, 23]]], ['t3', 'person', [[37, 40]]], ['t4', 'person', [[50, 61]]], ], };
i need create java class can used create json above structure using gson.
this have:
public class docdata { private string text; private list<list<string>> entities; public docdata(final string text, final list<list<string>> entities) { this.text = text; this.entities = entities; } public list<list<string>> getentities() { return entities; } }
above class works serializing text
field not sure datatype need use entities
creates array of array of triplets form "['t1', 'person', [[0, 11]]]"
.
your code fine json
provided.
however:
the entities
mix of types.
each entity
in entities
array
.
there 3 element in entity
: string
, string
, array
this not recommended way. suggest use:
{ "text": "ed o'kelley man shot man shot jesse james.", "entities": [ { "field_name_1": "t1", "field_name_2": "person", "field_name_3": [ [ 0, 11 ] ] } ... ] }
in case have 2 pojo
's:
public class docdata { private string text; private list<entity> entities; public docdata(final string text, final list<entity> entities) { this.text = text; this.entities = entities; } public list<entity> getentities() { return entities; } } public class entity { private string field_name_1; private string field_name_2; private list<list<integer>> field_name_3; }
Comments
Post a Comment