Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a logic problem in your code. You want to loop until you reach the end of the object but break your loop with return b (if block). This means that you will not read the object stream until its end. </p> <p>Try something like this (didn't try it but should work).</p> <pre><code>public class MyReferenceObjectCodeDeserializer extends JsonDeserializer&lt;MyReferenceObjectBean&gt; { @Override public ColumnReferenceBean deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { MyReferenceObjectBean b = null; while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); jp.nextToken(); if ("code".equalsIgnoreCase(fieldname)) { b = MyReferenceObjectServiceImpl.retrieveByCode(jp.getText()); logger.info("returning " +b.toString()); } } if (b==null) logger.info("returning null"); return b; } } </code></pre> <p>You can also have a look at Genson <a href="http://code.google.com/p/genson/" rel="nofollow">http://code.google.com/p/genson/</a> if you can change from jackson. In addition of some other features it is supposed to be easier to use. Here is how you can solve your problem with genson (for this example it is quite similar to jackson):</p> <pre><code>public class MyReferenceObjectCodeDeserializer implements Deserializer&lt;MyReferenceObjectBean&gt; { public MyReferenceObjectBeandeserialize(ObjectReader reader, Context ctx) throws TransformationException, IOException { MyReferenceObjectBean b = null; reader.beginObject(); while (reader.hasNext()) { reader.next(); if ("code".equalsIgnoreCase(reader.name())) b = MyReferenceObjectServiceImpl.retrieveByCode(reader.valueAsString()); } reader.endObject(); return b; } } // register it Genson genson = new Genson.Builder().withDeserializers(new MyReferenceObjectCodeDeserializer()).create(); MyClass myClass = genson.deserialize(json, MyClass.class); </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.
 

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