[xstream-user] Problem with convert to XML!

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[xstream-user] Problem with convert to XML!

Inocêncio Oliveira
Hi all,
 
I have in my issue 3 model class (ObjectMsgType, User and Message) that you can see below...
 

package org.grinvon.network;

public class ObjectMsgType {
 
 private String type;
 private User user;
 private Message message;
 
 public void setType(String type) {
  this.type = type;
 }
 
 public String getType() {
  return type;
 }
 
 public void setUser(User user) {
  this.user = user;
 }
 
 public User getUser() {
  return user;
 }
 
 public void setMessage(Message message) {
  this.message = message;
 }
 
 public Message getMessage() {
  return message;
 }

}

and...

package org.grinvon.network;

public class User {

 private  String name;
 private int status;
 
 public void setName(String name) {
  this.name = name;
 }
 
 public String getName() {
  return name;
 }
 
 public void setStatus(int status) {
  this.status = status;
 }
 
 public int getStatus() {
  return status;
 }
 
}

and last one...

package org.grinvon.network;

public class Message {
 
 private String sendTo;
 private String from;
 private String msg;
 private String msgType;
 
 public void setSendTo(String sendTo) {
  this.sendTo = sendTo;
 }
 
 public String getSendTo() {
  return sendTo;
 }
 
 public void setFrom(String from) {
  this.from = from;
 }
 
 public String getFrom() {
  return from;
 }
 
 public void setMsg(String msg) {
  this.msg = msg;
 }
 
 public String getMsg() {
  return msg;
 }
 
 public void setMsgType(String msgType) {
  this.msgType = msgType;
 }
 
 public String getMsgType() {
  return msgType;
 }

}

ObjectMsgType can receive Message class and User class, I use theses class to communicate a Client with a Server socket.

So.. I can send a ObjectMsgType class with 2 models (Message and User).

But when I convert the ObjectMsgType to XML with Message, User or both, it´s don´t convert the ObjectMsgType to correct XML. See example below...

    ObjectMsgType type = new ObjectMsgType();
    User user = new User();
    user.setName("Inocencio");
    
    type.setType("USER");
    type.setUser(user);
    type.setMessage (null);
    
    XStream stream = new XStream();
    stream.alias("obj",ObjectMsgType.class);
    stream.alias("user",User.class);

    String output = stream.toXML(type);

    ...................

When I print to console the XML created, it´s bring me a XML String like that...

<obj>

<type>USER</type>

<user/>               <::: problem is here, he close the tag without nodes

</obj>

 I cannot understand why XStream being making it. I have tried with many different ways and all time I send a wrong XML to the Server.

Please I need urgent help! Thanks all!

Reply | Threaded
Open this post in threaded view
|

[xstream-user] Re: Problem with convert to XML!

Mauro Talevi
Inoc?ncio Oliveira wrote:

>     ...................
>
> When I print to console the XML created, it?s bring me a XML String like
> that...
>
> <obj>
>
> <type>USER</type>
>
> *<user/>               <::: problem is here, he close the tag without nodes*
>
> </obj>
>
>  I cannot understand why XStream being making it. I have tried with many
> different ways and all time I send a wrong XML to the Server.
>

Hi,

have you tried serialising only the User class with XStream?
That would probably give us some clue as to what may be going on.

Cheers