Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when generating schema for class with JsonValue annotation over Collection/Array #34

Closed
peshitz opened this issue Apr 1, 2014 · 5 comments
Milestone

Comments

@peshitz
Copy link

peshitz commented Apr 1, 2014

When trying to generate jsonSchema for the following class, an NPE is raised.
jackson-databind version is 2.2.3.

public class Histogram{

    ...
    @JsonValue
    public Collection<String> asCollection() {...}

    }
java.lang.NullPointerException
    at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.acceptJsonFormatVisitor(AsArraySerializerBase.java:255)
    at com.fasterxml.jackson.databind.ser.std.JsonValueSerializer.acceptJsonFormatVisitor(JsonValueSerializer.java:269)
    at com.fasterxml.jackson.databind.ser.std.JsonValueSerializer.acceptJsonFormatVisitor(JsonValueSerializer.java:269)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.acceptJsonFormatVisitor(DefaultSerializerProvider.java:281)
    at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:2673)
@cowtowncoder
Copy link
Member

Thanks. I assume this also occurs with 2.3.2.

@greyfairer
Copy link

Same occurs in 2.3.2 and in 2.4.2.

The problem seems to be in AsArraySerializerBase.java:

    @Override
    public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
        throws JsonMappingException
    {
        JsonArrayFormatVisitor arrayVisitor = (visitor == null) ? null : visitor.expectArrayFormat(typeHint);
        if (arrayVisitor != null) {
            TypeFactory tf = visitor.getProvider().getTypeFactory();
            JavaType contentType = tf.moreSpecificType(_elementType, typeHint.getContentType());

Here, typeHint is null for a List/Set used in a @JsonValue

cowtowncoder added a commit to FasterXML/jackson-databind that referenced this issue Sep 2, 2014
@cowtowncoder cowtowncoder added this to the 2.4.3 milestone Sep 2, 2014
@cowtowncoder
Copy link
Member

Fixed this in jackson-databind; added a unit test here and it passes against 2.4.3-SNAPSHOT.
Not planning to backport in 2.3 because change in databind not trivial (want to minimize any chance of regression for 2.3).

@greyfairer
Copy link

This bug seems not to be completely fixed. It doesn't throw a NPE anymore, but it doesn't generate the schema correctly either. It just generates:

    {
        "type":"array"
    }

I extended the test to use a collection of nested beans, and expected to see the schema of the nested items, e.g.:

    {
      "type" : "array",
      "items" : {
        "type" : "object",
        "properties" : {
          "property1" : {
            "type" : "integer"
          },
          "property2" : {
            "type" : "string"
          }
        }
      }
    }

See updated test:
greyfairer@2a9b859

@cowtowncoder
Copy link
Member

Sounds like related bug (something that was masked by NPE most likely). I'll create a new issue since it may take longer to figure out this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants