使用JAXB2Marshaller解组传入的JSON请求

时间:2017-01-30 15:37:56

标签: json jaxb marshalling unmarshalling

我有以下spring配置:

<bean id="exportMarshallerJson" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="contextPaths">
        <list>
            <value>com.foo.bar.export.jaxb</value>
        </list>
    </property>
    <property name="schemas">
        <list>
            <value>classpath:exportxsd/schema.xsd</value>
        </list>
    </property>
    <property name="marshallerProperties">
        <map>
            <entry key="eclipselink.media-type">
                <value>application/json</value>
            </entry>
            <entry key="eclipselink.json.include-root">
                <value type="java.lang.Boolean">true</value>
            </entry>
            <entry key="jaxb.encoding">
                <value>UTF-8</value>
            </entry>
            <entry key="jaxb.formatted.output">
              <value type="java.lang.Boolean">true</value>
            </entry>
        </map>
    </property>
    <property name="unmarshallerProperties">
        <map>
            <entry key="eclipselink.media-type">
                <value>application/json</value>
            </entry>
            <entry key="eclipselink.json.include-root">
                <value type="java.lang.Boolean">true</value>
            </entry>
        </map>
    </property>
</bean>

现在,我可以使用上面的marshaller将Java对象编组为JSON字符串,但是传入的JSON字符串不能通过上面的unmarshaller正确地解组。

例外是:

  

[致命错误]:1:1:prolog中不允许使用内容。

我不能使用Jackson或其他JSON unmarshallers,因为我的要求是验证XSD。

我试图调试,看起来像底层&#34; platformUnmarshaller&#34;永远不会得到eclipselink.mediatype属性&#34; application / json&#34;。

提前感谢任何指示!

0 个答案:

没有答案
相关问题