-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
I'm using jackson 2.9.1
I'm trying to get JSON schema as following :
import org.junit.Test;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jsonSchema.JsonSchema;
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
public class SchemaGenerationTest {
public static class Item {
public String test;
}
@JsonRootName("root")
public static class RootName {
public Item[] items;
@JsonCreator
public RootName(Item[] queries) {
this.items = items;
}
@JsonValue
public Item[] getItems() {
return items;
}
}
/**
* This throws an NPE :
*
* java.lang.NullPointerException
* at com.fasterxml.jackson.databind.ser.std.ObjectArraySerializer.acceptJsonFormatVisitor(ObjectArraySerializer.java:316)
* at com.fasterxml.jackson.databind.ser.std.JsonValueSerializer.acceptJsonFormatVisitor(JsonValueSerializer.java:265)
* at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.acceptJsonFormatVisitor(DefaultSerializerProvider.java:566)
* at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:3862)
*/
@Test
public void testSchema() throws Exception {
ObjectMapper mapper = new ObjectMapper();
JavaType type = mapper.constructType(RootName.class);
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(type, visitor);
JsonSchema jsonSchema = visitor.finalSchema();
try {
System.out.println(mapper
.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}
But when I'm running the test I get this exception:
java.lang.NullPointerException
at com.fasterxml.jackson.databind.ser.std.ObjectArraySerializer.acceptJsonFormatVisitor(ObjectArraySerializer.java:316)
at com.fasterxml.jackson.databind.ser.std.JsonValueSerializer.acceptJsonFormatVisitor(JsonValueSerializer.java:265)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.acceptJsonFormatVisitor(DefaultSerializerProvider.java:566)
at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:3862)
I'm suspecting JsonValueSerializer#acceptJsonFormatVisitor
.
It returns ser.acceptJsonFormatVisitor(visitor, null);
leading to the NPE in ObjectArraySerializer
Metadata
Metadata
Assignees
Labels
No labels