Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to stick with strictly <code>gson</code> you can provide a custom <a href="http://google-gson.googlecode.com/svn/tags/gson-1.7.1/docs/javadocs/com/google/gson/JsonDeserializer.html" rel="nofollow">deserializer</a>. Since we know that <code>service</code> is either a property of the base <code>json</code> string or embedded within some other <code>property</code>, we can use the deserializer to step-wise parse out the offending components and handle them accordingly.</p> <pre><code> public class MyJsonDeserializer implements JsonDeserializer&lt;YourParsedData&gt; { @Override public YourParsedData deserialize(final JsonElement je, final Type type, final JsonDeserialization Context jdc) throws JsonParseException { final JsonObject obj = je.getAsJsonObject(); //our original full json string final JsonElement serviceElement = obj.get("service"); //here we provide the functionality to handle the naughty element. It seems emtpy string is returned as a JsonPrimitive... so one option if(serviceElement instanceOf JsonPrimitive) { //it was empty do something } return YourParsedData.create(); //provide the functionality to take in the parsed data } } </code></pre> <p>The custom deserializer would be called as follows:</p> <pre><code> final Gson gson = new GsonBuilder().registerTypeAdapter(YourParsedData.class, new MyJsonDeserializer()).create(); gson.fromJson("{service: ''}", YourParsedData.class); </code></pre> <p>I typed all this up so if I missed some syntax my apologies.</p>
    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. 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