Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this with custom deserializer. At the start we should create data model which can represent your JSON.</p> <pre><code>class JsonEntity { private List&lt;Movie&gt; movies; public List&lt;Movie&gt; getMovies() { return movies; } public void setMovies(List&lt;Movie&gt; movies) { this.movies = movies; } @Override public String toString() { return "JsonEntity [movies=" + movies + "]"; } } class Movie { private String title; private Profile in_wanted; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Profile getIn_wanted() { return in_wanted; } public void setIn_wanted(Profile in_wanted) { this.in_wanted = in_wanted; } @Override public String toString() { return "Movie [title=" + title + ", in_wanted=" + in_wanted + "]"; } } class Profile { private boolean value; public boolean isValue() { return value; } public void setValue(boolean value) { this.value = value; } @Override public String toString() { return String.valueOf(value); } } </code></pre> <p>Now when we have all needed classes we should implement new custom deserializer:</p> <pre><code>class ProfileJsonDeserializer implements JsonDeserializer&lt;Profile&gt; { @Override public Profile deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { if (jsonElement.isJsonPrimitive()) { return null; } return context.deserialize(jsonElement, JsonProfile.class); } } class JsonProfile extends Profile { } </code></pre> <p>Please have a look on <code>JsonProfile</code> class. We have to create it to avoid "deserialization loop" (tricky part).</p> <p>And now we can test our solution with test method:</p> <pre><code>GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Profile.class, new ProfileJsonDeserializer()); Gson gson = builder.create(); JsonEntity jsonEntity = gson.fromJson(new FileReader("/tmp/json.txt"), JsonEntity.class); System.out.println(jsonEntity); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload