@JacksonInject

@JacksonInject is used to indicate a property that will get its value from the injection and not from the JSON data.

In the following example - we use @JacksonInject to inject to the property id;

public class BeanWithInject{
    @JacksonInject
    public int id;

    public String name;
}

And here's how this works:

@Test
public void whenDeserializingUsingJsonInject_thenCorrect() throws IOException{
    String json = "{\"name\":\"My bean\"}";

    InjectableValues inject = new InjectableValues.Std()
            .addValue(int.class, 1);
    BeanWithInject bean = new ObjectMaper().reader(inject)
            .forType(BeanWithInject.class)
            .readValue(json);

    assertEquals("My bean", bean.name);
    assertEquals(1, bean.id);

results matching ""

    No results matching ""