反序列化XML消息时遇到此错误:
无法识别的字段“ schemaLocation”(com.example.RefreshTokenType类),未标记为可忽略(4个已知属性:“ authorized_party”,“ audience”,“ meta”,“ client_id”])。
ID Time_Stamp A B C
1 02/02/2018 07:45:00 123 567 434
2 02/02/2018 07:45:01
..... ...
5 02/02/2018 07:46:00 mean(A)
5.1 02/02/2018 07:46:01 mean(A) mean(b) mean(c)
5.2 02/02/2018 07:46:02 mean(A) mean(b) mean(c)
5.3 02/02/2018 07:46:03 mean(A) mean(b) mean(c)
5.4 02/02/2018 07:46:04 mean(A) mean(b) mean(c)
5.5 02/02/2018 07:46:05 mean(A) mean(b) mean(c)
5.6 02/02/2018 07:46:06 mean(A) mean(b) mean(c)
5.7 02/02/2018 07:46:07 mean(A) mean(b) mean(c)
5.8 02/02/2018 07:46:08 mean(A) mean(b) mean(c)
5.9 02/02/2018 07:46:09 mean(A) mean(b) mean(c)
6 02/02/2018 07:46:10 112 2323 2323
背景是我要从 org.eclipse.persistence.moxy 切换到 FasterXML / Jackson 以便用Jersey封送JSON和XML。一切正常,直到得到包含 schemaLocation 的XML消息。
这是我的反序列化设置:
<p:RefreshToken authorized_party="" client_id="15d8b31f4823aeaf21d3ba6ee87a4557"
xmlns:p="http://example.com/xsd/oauth/v2/oauth-spec.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/xsd/oauth/v2/oauth-spec.xsd oauth-v2-spec.xsd ">
<p:meta id="meta111" locale="*" name="x" value="x" />
</p:RefreshToken>
这是我的http://example.com/xsd/oauth/v2/oauth-spec.xsd的摘录:
public static void enableDeserializationSetting(ObjectMapper reader) {
Set<Class<?>> jaxbClasses = collectJaxbAnnotatedClasses();
reader.registerModule(new JaxbAnnotationModule());
reader.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
reader.registerSubtypes(jaxbClasses);
}
有人可以照亮吗?
答案 0 :(得分:0)
您可以在ObjectMapper
中禁用FAIL_ON_UNKNOWN_PROPERTIES
功能:
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
或者,您可以使用@JsonIgnoreProperties
将ignoreUnknown
设置为true
:
@JsonIgnoreProperties(ignoreUnknown = true)
public class RefreshTokenType {
...
}