Roberto
Roberto

Reputation: 1395

There is null value in field when parse xml from request by jaxb?

I have application on spring+maven+jaxb. There is rest controller

@RequestMapping(value = "/risks", method = RequestMethod.POST)
    public void addRisks(@RequestBody RiskMetric risks) {
        risksService.addriks(risks);
    }

which need to parse xml to entity Risk like this

<Risks>
  <test>111</test>
  <param>
    <type>testType</type>
  /param>
  <currency>UYU</currency>
</Risks>

but, in created Risk-entity there is null in field type. Risk entity:

@XmlRootElement(name = "Risks")
@XmlAccessorType(XmlAccessType.FIELD)
public class Risks implements Serializable {
    @XmlElement
    private String test;

    @XmlElement
    @XmlJavaTypeAdapter(ParamAdapter.class)
    private Param param;

    @XmlJavaTypeAdapter(CurrencyAdapter.class)
    @XmlElement
    private Currency currency;
    ...constructors and getters\setters..

ParamAdapter is:

public class ParamAdapter extends XmlAdapter<String, Param> {

    @Override
    public Param unmarshal(String v) throws Exception {
        return new Param(v);
    }

    @Override
    public String marshal(Param v) throws Exception {
        StringBuilder result = new StringBuilder();
        result.append(v.getType());
        return result.toString();
    }
}

and Param - class is:

public class Param implements Serializable {

    @XmlElement
    private String type;
...construcors and getters and setters..
}

Do I need to create other adapter for Param class or there is other way to solve this issue?

p.s. under debug flow is visit unmarshal method and input string parameter is "\n" - empty string

Upvotes: 0

Views: 371

Answers (1)

Roberto
Roberto

Reputation: 1395

removed all faster.xml dependecies and added jaxb. Problem solved.

Upvotes: 1

Related Questions