ข้อผิดพลาด MOXyJsonProvider เมื่อยกเลิกการจัดเรียงอาร์เรย์ json

ฉันมีทรัพยากรเสื้อแบบธรรมดา UserContentManager ที่ประมวลผลคลาส ContentInput แบบธรรมดา ทั้งสองคลาสอยู่ด้านล่าง เมธอด postHello ทำงานได้ดีเมื่อถูกเรียกโดยใช้ curl -X POST -H "Content-Type: application/json" -d '{"id":1,"type":"a"}' localhost:50000/news/rest/hello แต่เมธอด putHello นั้นล้มเหลวเมื่อถูกเรียกด้วย curl -X PUT -H "Content-Type: application/json" -d '[{"id":1}]' localhost:50000/news/rest/hello

มันล้มเหลวใน MOXyJsonProvider:598 (บรรทัดที่เป็นตัวหนาด้านล่าง) เพราะเมื่อไม่ได้จัดเรียงข้อมูล มันจะถูกยกเลิกการจัดเรียงเป็น ArrayList<Property> แทนที่จะเป็น ArrayList<JAXBElement<Property>> ตามที่โค้ดคาดหวัง นั่นคือ Object value = jaxbElement.getValue() คือ ArrayList<Property> ไม่ใช่ ArrayList<JAXBElement> เหมือนการส่ง .

นี่เป็นจุดบกพร่องใน Moxy หรือฉันกำลังทำอะไรผิดหรือเปล่า? เมธอด getArray ทำงานได้ดีเมื่อส่งคืนอาร์เรย์ ฉันได้ลองแล้วโดยมีและไม่มี @XmlRootElement ในคลาส ContentInput แต่ผลลัพธ์ก็เหมือนกัน

        JAXBElement<?> jaxbElement = unmarshaller.unmarshal(jsonSource, domainClass);
        if(type.isAssignableFrom(JAXBElement.class)) {
            return jaxbElement;
        } else {
            Object value = jaxbElement.getValue();
            if(value instanceof ArrayList) {
                if(type.isArray()) {
                    ArrayList<JAXBElement> arrayList = (ArrayList<JAXBElement>) value;
                    int arrayListSize = arrayList.size();
                    Object array;
                    if(genericType instanceof GenericArrayType) {
                        array = Array.newInstance(JAXBElement.class, arrayListSize);
                        for(int x=0; x<arrayListSize; x++) {
                            Array.set(array, x, arrayList.get(x));
                        }
                    } else {
                        array = Array.newInstance(domainClass, arrayListSize);
                        for(int x=0; x<arrayListSize; x++) {

* Array.set(อาร์เรย์, x, arrayList.get(x).getValue());*

                        }
                    }
                    return array;

@WebService
@Path("/hello")
public class UserContentManager {

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response postHello(ContentInput input) {
    input.setId(input.getId());
    input.setType("clip" + input.getType());
    ResponseBuilder builder = Response.ok();
        builder.entity(input);
    return builder.build();
}

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ContentInput[] putHello(ContentInput [] input) {
    return input;
}

@Path("/array")
@GET
@Produces(MediaType.APPLICATION_JSON)
public ContentInput[] getArray() {
    return new ContentInput[] {
            new ContentInput(),
            new ContentInput()
    };
}

}


public class ContentInput {
private int id;
private String type;

public ContentInput() {}

public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getType() {
    return type;
}
public void setType(String type) {
    this.type = type;
}

}


person user2755861    schedule 06.09.2013    source แหล่งที่มา


คำตอบ (1)


หมายเหตุ: ฉันคือ EclipseLink JAXB (MOXy) ผู้นำและสมาชิกของ JAXB (JSR-222) กลุ่มผู้เชี่ยวชาญ

คุณกำลังพบจุดบกพร่องต่อไปนี้ซึ่งเราได้แก้ไขใน EclipseLink 2.5.1:

person bdoughan    schedule 09.09.2013