Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jackson Java EE WS-XML为空,但JSON具有所有字段_Java_Json_Xml_Web Services - Fatal编程技术网

Jackson Java EE WS-XML为空,但JSON具有所有字段

Jackson Java EE WS-XML为空,但JSON具有所有字段,java,json,xml,web-services,Java,Json,Xml,Web Services,我有一个POJO,我正在通过REST服务公开: @XmlRootElement public class Field implements Serializable{ /** * */ @JsonIgnore private static final long serialVersionUID = 1L; FieldType fieldType; String name; Object deafultValue;

我有一个POJO,我正在通过REST服务公开:

@XmlRootElement
public class Field implements Serializable{
    /**
     * 
     */
    @JsonIgnore
    private static final long serialVersionUID = 1L;

    FieldType fieldType;

    String name;

    Object deafultValue;

    Map<String, String> choices;

    boolean required;

    public Field(){}

    @JsonCreator
    public Field(@JsonProperty("fieldType") FieldType fieldType, String name, Object deafultValue, Map<String, String> choices, boolean required) {
        super();
        this.fieldType = fieldType;
        this.name = name;
        this.deafultValue = deafultValue;
        this.choices = choices;
        this.required = required;
    }

    @JsonProperty 
    public FieldType getFieldType() {
        return fieldType;
    }

    @Override
    public String toString() {
        return "Field [fieldType=" + fieldType + ", name=" + name + ", deafultValue=" + deafultValue + ", choices="
                + choices + ", required=" + required + "]";
    }

    public String getName() {
        return name;
    }

    public Object getDeafultValue() {
        return deafultValue;
    }

    public Map<String, String> getChoices() {
        return choices;
    }

    public boolean isRequired() {
        return required;
    }

}
日志消息显示数据已存在:

DEBUG ActorsFacadeREST-获取参与者搜索字段:[Field[fieldType=INPUT,name=name,deafultValue=null,choices=null,required=true]]

当我查询JSON时:

$ curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:8080/actor-service/webresources/entities.actors/search-fields/ && echo ""
HTTP/1.1 200 OK
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/10
Content-Type: application/json
Content-Length: 88
Date: Sun, 20 Mar 2016 13:44:46 GMT

[{"fieldType":"INPUT","name":"Name","deafultValue":null,"choices":null,"required":true}]
当我要求XML时:

$ curl -i -H "Accept: application/xml" -H "Content-Type: application/json" -X GET http://localhost:8080/actor-service/webresources/entities.actors/search-fields/ && echo ""
HTTP/1.1 200 OK
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/10
Content-Type: application/xml
Content-Length: 88
Date: Sun, 20 Mar 2016 13:46:47 GMT

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><collection><field/></collection>

我认为您还必须用@xmlement注释字段…

好的,我发布了一个工作对象(在上面的编辑中)。为什么它不需要它们?
$ curl -i -H "Accept: application/xml" -H "Content-Type: application/json" -X GET http://localhost:8080/actor-service/webresources/entities.actors/search-fields/ && echo ""
HTTP/1.1 200 OK
Connection: keep-alive
X-Powered-By: Undertow/1
Server: WildFly/10
Content-Type: application/xml
Content-Length: 88
Date: Sun, 20 Mar 2016 13:46:47 GMT

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><collection><field/></collection>
public class Actor implements Serializable, HasImage, Searchable<Actor> {
    private static final transient Logger L = LoggerFactory.getLogger(Actor.class);
    private static final long serialVersionUID = 1L;

    private Long id;

    private String eid;

    private String name;

    private String status;

    private String reportsToEid;

    private String email;

    String imageLocation;


    PathType pathType;

    public Actor() {
        L.debug("Actor created with default constructor");
    }

    @JsonCreator
    public Actor(@JsonProperty("id") Long id, @JsonProperty("eid") String eid, @JsonProperty("name")String name, 
            @JsonProperty("status") String status, @JsonProperty("reportsToId") String reportsToEid, 
            @JsonProperty("email") String email, @JsonProperty("imageLocation")String imageLocation, 
            @JsonProperty("pathType") PathType pathType) {
        super();
        L.debug("Actor created with JsonCreator marked constructor");
        this.id = id;
        this.eid = eid;
        this.name = name;
        this.status = status;
        this.reportsToEid = reportsToEid;
        this.email = email;
        this.imageLocation = imageLocation;
        this.pathType = pathType;
    }