Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

@JsonAppend causes NullPointerException #57

Closed
cleiner opened this issue Aug 19, 2015 · 0 comments
Closed

@JsonAppend causes NullPointerException #57

cleiner opened this issue Aug 19, 2015 · 0 comments
Milestone

Comments

@cleiner
Copy link

cleiner commented Aug 19, 2015

Afterburner does not seem to work with @JsonAppend. The following code reproduces the issue:

  @Test
  public void testJsonAppendWithAfterburner() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new AfterburnerModule());
    String json = mapper.writeValueAsString(new Pojo("foo"));
    assertEquals("{\"name\":\"foo\",\"virtual\":\"bar\"}", json);
  }


  @JsonAppend(props = @Prop(name = "virtual", value = MyVirtualPropertyWriter.class))
  public static class Pojo {
    private final String name;
    public Pojo(String name) {
      this.name = name;
    }
    public String getName() {
      return name;
    }
  }

  public static class MyVirtualPropertyWriter extends VirtualBeanPropertyWriter {
    public MyVirtualPropertyWriter() {
    }
    protected MyVirtualPropertyWriter(BeanPropertyDefinition propDef, Annotations contextAnnotations,
        JavaType declaredType) {
      super(propDef, contextAnnotations, declaredType);
    }
    @Override
    protected Object value(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception {
      return "bar";
    }
    @Override
    public VirtualBeanPropertyWriter withConfig(MapperConfig<?> config, AnnotatedClass declaringClass,
        BeanPropertyDefinition propDef, JavaType type) {
      return new MyVirtualPropertyWriter(propDef, declaringClass.getAnnotations(), type);
    }
  }

Running the test results in:

java.lang.NullPointerException
    at com.fasterxml.jackson.module.afterburner.ser.SerializerModifier.findProperties(SerializerModifier.java:82)
    at com.fasterxml.jackson.module.afterburner.ser.SerializerModifier.changeProperties(SerializerModifier.java:49)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:374)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:272)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:225)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:153)
    at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1199)
    at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1153)
    at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:481)
    at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:679)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:107)
    at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3525)
    at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2915)
    at com.bitlok.JsonAppendTest.testJsonAppendWithAfterburner(JsonAppendTest.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

I've tested this with 2.6.1. Without the AfterburnerModule it works as expected.

@cowtowncoder cowtowncoder modified the milestones: 2.2.1, 2.6.2 Sep 11, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants