0

I'm developing a JERSEY RESTFUL web service which has a function that accept an object parameter. It is called "Synchronize" and looks like this:

@XmlRootElement
public class Synchronize {

private List<PHQ9> phq9OutOfSync;
private List<ExtraQuestions> extraQuestionsOutOfSync;
private List<Suicide> suicideOutOfSync;
private List<Brugha> brughaOutOfSync;
private int hola;

public Synchronize() {

    phq9OutOfSync = new ArrayList<PHQ9>();
    extraQuestionsOutOfSync = new ArrayList<ExtraQuestions>();
    suicideOutOfSync = new ArrayList<Suicide>();
    brughaOutOfSync = new ArrayList<Brugha>();
}
}

The problem is I am not able to send a xml with the serialization of this class to the web service. I send an xml with all the attributes but it doesn't deserialize it well... I don't know if it is because the Lists that are doing some problems or so. I even tried sending only the int attribute like:

<synchronize><hola>1</hola></synchronize>

and doesn't work too... What is going on?

Any hints?

EDIT: I'm seeing that I don't know how I can refer to an attribute that is in a class. I tried making a web service that accepts a list with phq9 objects, and it works great, but if I put that list in other class, then it doesn't know how to deserialize. Why could it be?

EDIT2:

@XmlRootElement
public class PHQ9 {

@XmlElement
private int id;
@XmlElement
private int patientId;
@XmlElement
private int answer1;
@XmlElement
private int answer2;
@XmlElement
private int answer3;
@XmlElement
private int answer4;
@XmlElement
private int answer5;
@XmlElement
private int answer6;
@XmlElement
private int answer7;
@XmlElement
private int answer8;
@XmlElement
private int answer9;
@XmlElement
private int answer10;
@XmlElement
private int total;
@XmlElement
private int week;
@XmlElement
private String phq9Date;
@XmlElement
private String timeExported;
@XmlElement
private String dateExported;
@XmlElement
private int exported;

public PHQ9() {

    phq9Date = timeExported = dateExported = "";        
}
}
Frion3L
  • 1,502
  • 4
  • 24
  • 34

1 Answers1

0

[EDIT]

In regards to lists, take a look at JAXB: How to marshal objects in lists? on how to wrap lists, if desired.

You can limit which members are to be serialized using XmlAccessorType (http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/XmlAccessorType.html) and XmlElement (http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/XmlElement.html).

It is possible you are trying to serialize/deserialize an unsupported class, causing it to fail. Are you getting any exceptions or is it just failing silently? Have you tried taking a look at the raw data being sent/received?

Community
  • 1
  • 1
Kevin Mangold
  • 1,167
  • 8
  • 21
  • Can you explain it a bit more? – Frion3L Jun 25 '12 at 19:06
  • My apologies, I think I misunderstood your question. Let me work up an edit to my response. – Kevin Mangold Jun 25 '12 at 19:12
  • I added XMLElement to the attributes of the class Synchronize and now it seems to go better. Now tha attribute "hola" is deserialized well but the other ones not. It deserialized the size of the array, but the attributes of the objects that are in not... they have the initial values. Any hint? (I added XMlElement to the attributes of the objects in the array, but it doesn't work). Thanks – Frion3L Jun 25 '12 at 19:25
  • Can you post the SC of the classes that are only getting initial values? – Kevin Mangold Jun 25 '12 at 19:31
  • sure, posted! I don't know what it could be – Frion3L Jun 25 '12 at 19:46
  • Try adding the XmlType annotation to the classes being serialized, too. – Kevin Mangold Jun 25 '12 at 19:48