Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>LongJsonDeserializer deserializer = new LongJsonDeserializer(); SimpleModule module = new SimpleModule("LongDeserializerModule", new Version(1, 0, 0, null, null, null)); module.addDeserializer(Long.class, deserializer); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); </code></pre> <hr> <p>Here's a full demo application. This works with the latest release of Jackson, and probably also with Jackson versions going back to 1.7.</p> <pre><code>import java.io.IOException; import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonProcessingException; import org.codehaus.jackson.Version; import org.codehaus.jackson.map.DeserializationContext; import org.codehaus.jackson.map.JsonDeserializer; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.module.SimpleModule; public class Foo { public static void main(String[] args) throws Exception { TestBean bean = new TestBean(); bean.value = 42L; ObjectMapper mapper = new ObjectMapper(); String beanJson = mapper.writeValueAsString(bean); System.out.println(beanJson); // output: {"value":42} TestBean beanCopy1 = mapper.readValue(beanJson, TestBean.class); System.out.println(beanCopy1.value); // output: 42 SimpleModule module = new SimpleModule("LongDeserializerModule", new Version(1, 0, 0, null)); module.addDeserializer(Long.class, new LongJsonDeserializer()); mapper = new ObjectMapper(); mapper.registerModule(module); TestBean beanCopy2 = mapper.readValue(beanJson, TestBean.class); System.out.println(beanCopy2.value); // output: 126 } } class TestBean { Long value; public Long getValue() {return value;} public void setValue(Long value) {this.value = value;} } class LongJsonDeserializer extends JsonDeserializer&lt;Long&gt; { @Override public Long deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { Long value = jp.getLongValue(); return value * 3; } } </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