我有一个实体类,看起来像这样。
@XmlRootElement
public class ImageSuffix {
@XmlAttribute
private boolean canRead;
@XmlAttribute
private boolean canWrite;
@XmlValue;
private String value;
}
我正在使用以下依赖项来生成 JSON。
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.1.4</version>
</dependency>
当我尝试使用以下代码时,(参考Generating JSON Schemas with Jackson)
@Path("/imageSuffix.jsd")
public class ImageSuffixJsdResource {
@GET
@Produces({MediaType.APPLICATION_JSON})
public String read() throws JsonMappingException {
final ObjectMapper objectMapper = new ObjectMapper();
final JsonSchema jsonSchema =
objectMapper.generateJsonSchema(ImageSuffix.class);
final String jsonSchemaString = jsonSchema.toString();
return jsonSchemaString;
}
}
服务器抱怨以下错误消息
java.lang.IllegalArgumentException: Class com.googlecode.jinahya.test.ImageSuffix would not be serialized as a JSON object and therefore has no schema
at org.codehaus.jackson.map.ser.StdSerializerProvider.generateJsonSchema(StdSerializerProvider.java:299)
at org.codehaus.jackson.map.ObjectMapper.generateJsonSchema(ObjectMapper.java:2527)
at org.codehaus.jackson.map.ObjectMapper.generateJsonSchema(ObjectMapper.java:2513)
我怎样才能解决这个问题?