标签: moxy

我的jax-ws webservice客户端只返回空对象

我有一个第三方Web服务,我使用wsimport生成一个客户端.每次对webservice的调用都会成功完成,但我得到的响应对象的所有字段都设置为null.监控网络我可以看到,在线路上,响应消息中的所有XML元素都包含值,因此对象中应包含非空数据.此外,使用旧的axis1生成并使用相同数据调用的相同服务的客户端返回非空响应.知道发生了什么事吗?(如果它有任何区别我正在使用MOXy的JAXB实现).

更新:我已经能够缩小范围了.例如,wsdl在其自己的命名空间中定义对象http://www.acme.com/ws.我从服务中得到的回应是

<?xml version="1.0" encoding="UTF-8"?>
... SOAP envelope ...
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<result>6003</result>
<ndserr/>
<transid>61437594</transid>
<descriptionerr>BLAH.</descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
... SOAP closing tags ...
Run Code Online (Sandbox Code Playgroud)

并且被解组为非null OpINFOWLResponse,它包装非null responseINFOWL对象,并且所有字段都设置为null.为了好玩,我尝试编写几行来解​​组上面的代码片段(在剥离SOAP开销之后)

JAXBContext ctx = JAXBContext.newInstance(OpINFOWLResponse.class);
Unmarshaller u = ctx.createUnmarshaller();

OpINFOWLResponse o = (OpINFOWLResponse) u.unmarshal(new StringReader(theSnippetAbove));
ResponseINFOWL w = o.getResponseINFOWL();
Run Code Online (Sandbox Code Playgroud)

我得到了相同的结果.如果我将上面的XML更改为

<?xml version="1.0" encoding="UTF-8"?>
<ns1:opINFOWLResponse xmlns:ns1="http://www.acme.com/ws" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:responseINFOWL xsi:type="ns1:responseINFOWL">
<ns1:result>6003</ns1:result>
<ns1:ndserr/>
<ns1:transid>61437594</ns1:transid>
<ns1:descriptionerr>BLAH.</ns1:descriptionerr>
</ns1:responseINFOWL>
</ns1:opINFOWLResponse>
Run Code Online (Sandbox Code Playgroud)

一切正常.游民.

更新(再次):与jaxb-RI和Moxy相同的行为.还是不知道出了什么问题.

更新(9月9日):下面关于名称空间限定错误的建议很有意思,但我认为wsimport会把事情做对.无论如何,这是我的package-info.java

@XmlSchema(
namespace = "http://www.acme.com/ws", 
elementFormDefault = …
Run Code Online (Sandbox Code Playgroud)

java jax-ws jaxb moxy

8
推荐指数
1
解决办法
9962
查看次数

JAXB将多个XML元素解组为单个类

我有以下XML结构,它跨多个XML元素建模单个概念.这种格式不在我的掌控之中.

<Output>
  <Wrapper>
    <Channel>
      <id>1</id>
      <type>x</type>
    </Channel>
    <Channel>
      <id>2</id>
      <type>y</type>
    </Channel>
    <ChannelName>
      <id>1</id>
      <name>Channel name</name>
    </ChannelName>
    <ChannelName>
      <id>2</id>
      <name>Another channel name</name>
    </ChannelName>
  </Wrapper>
</Output>
Run Code Online (Sandbox Code Playgroud)

我想,我确实有控制权,并可以有一个更简单的数据库来模拟这个Channelid,typename领域.因此,我想List<Channel>Wrapper课堂上单独解组.

这可以@Xml...自动完成注释吗?我目前使用JAXB解组到单独@XmlElement(name="Channel")@XmlElement(name="ChannelName")类列表,然后将后处理瞬态ChannelName/nameChannel,但我想一定有这些元素映射一个更简单的自动化方式.或者它是XSLT的工作?

知道XML作为HTTP文件POST文件进入并且我正在使用Spring 3,Java和Hibernate可能会有所帮助.我希望EclipseLink JAXB(MOXy)中的某些东西可能有帮助:)

java xml jaxb eclipselink moxy

7
推荐指数
1
解决办法
5万
查看次数

JAXB 2.x:如何在不知道目标类的情况下解组XML?

如果有办法,怎么做,我想知道最优雅的一个.这是一个问题: - 假设你有一个抽象类Z - 你有两个从Z继承的类:名为A和B.

您封送任何实例(A或B),如下所示:

JAXBContext context = JAXBContext.newInstance(Z.class);
Marshaller m = context.createMarshaller();
m.marshal(jaxbObject, ...an outputstream...);
Run Code Online (Sandbox Code Playgroud)

在生成的XML中,您可以看到它是什么类型的实例(A或B).

现在,你如何解散呢?

JAXBContext jc = JAXBContext.newInstance(Z.class);
Unmarshaller u = jc.createUnmarshaller();
u.unmarshal(...an inputstream...)
Run Code Online (Sandbox Code Playgroud)

我得到一个UnmarshalException说

"Exception Description: A descriptor with default root element {<my namespace>}<the root tag, e.g. A or B> was not found in the project]
Run Code Online (Sandbox Code Playgroud)

javax.xml.bind.UnmarshalException"

那么你如何进行解组以便获得Z的实例然后你可以在解组后进行测试,它是什么?例如z instanceof A然后... z实例B然后别的东西......等等

感谢您的任何想法或解决方案.

我使用JRE1.6和MOXy作为JAXB Impl.

java jaxb jaxb2 moxy

7
推荐指数
1
解决办法
1万
查看次数

EclipseLink MOXy @XmlPath支持axis/parent

是否可以接受以下任何XPath表达式?使用eclipselink的2.3.1版

@XmlPath("../header/@type")
@XmlPath("/root/header/@type")
@XmlPath("parent::*/header/@type")
Run Code Online (Sandbox Code Playgroud)

基本上这是在XML文档(/root/tag)中重复的类中,如果不清楚我会详细说明.

我试图遍历树而不是向下.我的其他@XmlPath注释工作正常.

xpath jaxb eclipselink moxy

7
推荐指数
1
解决办法
1184
查看次数

MOXy反序列化异常:在项目中找不到具有默认根元素的描述符

这是我的课程:

@XmlRootElement(name="Zoo")
class Zoo {
    //@XmlElementRef
    public Collection<? extends Animal> animals;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({Bird.class, Cat.class, Dog.class})
@XmlDiscriminatorNode("@type")
abstract class Animal {
    @XmlElement
    public String name; 
}

@XmlDiscriminatorValue("Bird")
@XmlRootElement(name="Bird")
class Bird extends Animal {
    @XmlElement
    public String wingSpan;
    @XmlElement
    public String preferredFood;
}

@XmlDiscriminatorValue("Cat")
@XmlRootElement(name="Cat")
class Cat extends Animal {
    @XmlElement
    public String favoriteToy;
}

@XmlDiscriminatorValue("Dog")
@XmlRootElement(name="Dog")
class Dog extends Animal {
    @XmlElement
    public String breed;
    @XmlElement
    public String leashColor;
}
Run Code Online (Sandbox Code Playgroud)

这是序列化的JSON:

   {
        "animals": [
            {
                "type": "Bird",
                "name": "bird-1",
                "wingSpan": …
Run Code Online (Sandbox Code Playgroud)

java json moxy

7
推荐指数
1
解决办法
2万
查看次数

将Jersey和MOXy的JSON反序列化为List集合

我正在尝试将JSON对象放入一个集合中(我选择了List).通过使用适当的getter和setter创建BuiltCharacter,我已经能够将JSON响应解组为单个POJO.对于JSON元素数组,我尝试了以下方法:

List<BuiltCharacter> characters = response.readEntity(new GenericType<List<BuiltCharacter>>(){});
Run Code Online (Sandbox Code Playgroud)

List<BuiltCharacter> characters = client.target(uri).request(MediaType.APPLICATION_JSON).get(new GenericType<List<BuiltCharacter>>(){});
Run Code Online (Sandbox Code Playgroud)

使用这些方法得到了以下内容:

线程"main"中的异常java.lang.ClassCastException:BuiltCharacter无法强制转换为java.util.List

我最初使用Character作为类名,但提醒那是一个保留的类名.不过,我无法弄清楚这里发生了什么!

java json jersey moxy

7
推荐指数
1
解决办法
1329
查看次数

从JSON moxy输出重命名"type"

我正在努力解决Moxy如何处理对象的继承问题.

特别是,我需要重命名typeMoxy在子类型的情况下添加的默认元素,因为它阻止我type在我的对象中拥有自己的字段.

这个问题涉及从JSON输出泽西moxy删除"类型"但不幸的是,它没有回答我的问题.

我试图@XmlDiscriminatorNode在我的抽象类中包含一下,结果json似乎没有任何区别.

我也尝试完全删除默认的moxy type元素,但没有任何成功.

java json marshalling eclipselink moxy

7
推荐指数
1
解决办法
710
查看次数

避免在MOXy中创建对象包装器类型/值(JAXB + JSON)

我正在使用MOXy 2.6(JAXB + JSON).

我想以相同的方式编组ObjectElement和StringElement,但是当字段被输入为Object时,MOXy会创建包装器对象.

ObjectElement.java

public class ObjectElement {
    public Object testVar = "testValue";
}
Run Code Online (Sandbox Code Playgroud)

StringElement.java

public class StringElement {
    public String testVar = "testValue";
}
Run Code Online (Sandbox Code Playgroud)

Demo.java

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

import org.eclipse.persistence.jaxb.JAXBContextFactory;
import org.eclipse.persistence.jaxb.MarshallerProperties;
import org.eclipse.persistence.oxm.MediaType;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContextFactory.createContext(new Class[] { ObjectElement.class, StringElement.class }, null);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);

        System.out.println("ObjectElement:");
        ObjectElement objectElement = new ObjectElement();
        marshaller.marshal(objectElement, System.out);
        System.out.println();

        System.out.println("StringElement:");
        StringElement stringElement = new …
Run Code Online (Sandbox Code Playgroud)

java json jaxb moxy

7
推荐指数
1
解决办法
601
查看次数

HTTP使用JAX-RS REST-Service放置Enum

当我尝试通过HTTP PUT更新包含枚举的实体时,我在Jax-RS REST服务中遇到问题.

我将实体编码为JSON,因此我在此JSON中使用的枚举作为字符串传递.

我收到以下错误:

Exception [EclipseLink-43] (Eclipse Persistence Services - 2.6.2.qualifier): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Missing class for indicator field value [AGENT] of type [class java.lang.String].
Descriptor: XMLDescriptor(de.org.app.business.account.Account --> [DatabaseTable(account)])
    at org.eclipse.persistence.exceptions.DescriptorException.missingClassForIndicatorFieldValue(DescriptorException.java:940)
    at org.eclipse.persistence.internal.oxm.QNameInheritancePolicy.classFromRow(QNameInheritancePolicy.java:278)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.classFromRow(TreeObjectBuilder.java:182)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.classFromRow(TreeObjectBuilder.java:1)
    at org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl.initializeRecord(UnmarshalRecordImpl.java:512)
    at org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl.startElement(UnmarshalRecordImpl.java:748)
    at org.eclipse.persistence.internal.oxm.record.json.JsonStructureReader.parseRoot(JsonStructureReader.java:187)
    at org.eclipse.persistence.internal.oxm.record.json.JsonStructureReader.parse(JsonStructureReader.java:140)
    at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:978)
    at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:425)
    at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:375)
    at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:708)
    at org.eclipse.persistence.internal.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:643)
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:339)
    at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.readFrom(MOXyJsonProvider.java:668)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:256)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:235)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)
    at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:74)
    at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
    at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
    at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:271)
    at org.glassfish.jersey.server.internal.inject.EntityParamValueFactoryProvider$EntityValueFactory.provide(EntityParamValueFactoryProvider.java:96)
    at org.glassfish.jersey.server.spi.internal.ParamValueFactoryWithSource.provide(ParamValueFactoryWithSource.java:71) …
Run Code Online (Sandbox Code Playgroud)

java enums json jax-rs moxy

7
推荐指数
1
解决办法
910
查看次数

JAXB:Unmarshal异构数组

我正在尝试使用具有以下结构的MOXy json解组:

[
  {
    "page": 1,
    "pages": 1
  },
  [
    {
        "indicator": {
            "id": "IC.BUS.EASE.XQ",
            "value": "Ease of doing business index"
        },
        "country": {
            "id": "1A",
            "value": "Arab World"
        },
        "value": "113.952380952381",
        "date": "2014"
    },
    ...
    ]
]
Run Code Online (Sandbox Code Playgroud)

数组的第一个元素是一个对象,第二个元素是另一个复杂元素数组.我真的在SO和MOXy文档中搜索了一个类似的例子而没有任何成功.

我将json文档映射到JAVA类的最佳尝试如下.根类是CountryDataResponse(getters&setters ommited):

@XmlRootElement
@XmlType(propOrder ={"paginationInfo", "dataArray"})
public class CountryDataResponse {
    private DataArray dataArray;
    private PaginationInfo paginationInfo;
}
Run Code Online (Sandbox Code Playgroud)

(我可以看到这会失败,因为它不是一个数组,但我完全迷失了.)

PaginationInfo类为根数组的第一个元素建模,DataArray类包装第二个元素,即第二个元素数组.另外,我为每个Data元素中的复杂类型创建了Indicator和Country类.

主要类别(指标和国家省略):

@XmlRootElement(name = "paginationInfo")
@XmlAccessorType(XmlAccessType.FIELD)
public class PaginationInfo {

    private int page;
    private int pages;
}
Run Code Online (Sandbox Code Playgroud)
@XmlRootElement( name = "dataArray" )
public …
Run Code Online (Sandbox Code Playgroud)

java json jaxb unmarshalling moxy

6
推荐指数
1
解决办法
484
查看次数

标签 统计

moxy ×10

java ×9

jaxb ×6

json ×6

eclipselink ×3

enums ×1

jax-rs ×1

jax-ws ×1

jaxb2 ×1

jersey ×1

marshalling ×1

unmarshalling ×1

xml ×1

xpath ×1