Mike,

Here is my take with 3 classes:

public class Store {

  private int    storeNumber = 12345;
  private String storeName   = "Penn Street";
}

@XStreamAlias("stores")
public class Stores {
  @XStreamAsAttribute
  private String      desc   = "MULTIPLE_STORES";

  @XStreamImplicit(itemFieldName = "store")
  private List<Store> stores = Arrays.asList(new Store(), new Store());
}

@XStreamAlias("storeInfo")
public class StoreInfo {

  private String postalCode = "18055";
  private Stores stores     = new Stores();

  public static void main(String[] args) {
    XStream parser = new XStream();
    parser.processAnnotations(StoreInfo.class);
    StoreInfo si = new StoreInfo();
    System.out.println(parser.toXML(si));
  }
}

Hope this helps,
Christophe




Internet 
[email protected]
10/02/2012 20:06
Veuillez répondre à
[email protected]


Pour
[email protected]
cc

Objet
[xstream-user] How to configure XStream to unmarshal this xml






We utilize XStream quite a bit in our application and have been quite 
successful with it. However, I am stumped by how to configure XStream to 
unmarshal the following XML:
 
      <storeInfo>
        <postalCode>18055</postalCode>
        <stores desc="MULTIPLE_STORES">
          <store>
            <storeNumber>2167</storeNumber>
            <storeName>Penn Street Market</name>
          </store>
          <store>
            <storeNumber>1883</storeNumber>
            <storeName>AAA Northampton County</storeName>
          </store>
          <region>NORTHWEST</region>
        </stores>
      </storeInfo>
 
I have tried many different combinations of aliases (class, field, 
attribute) and different object hierarchies, but nothing seems to work.
 
Can you please assist? I have complete flexibility in the object 
hierarchy, so an recommendations on how to set up the object graph and 
XStream config would be greatly appreciated.
------------------------------ 
Mike Daleiden 
 
?Not everything that is said at you or to you is about you.? ? Joel C. 
Hunter
?Everyone should be quick to listen, slow to speak and slow to become 
angry.? ? James 1:19
 
 
 

  ________________________________ 
This communication (including all attachments) is intended solely for
the use of the person(s) to whom it is addressed and should be treated
as a confidential AAA communication. If you are not the intended
recipient, any use, distribution, printing, or copying of this email is
strictly prohibited. If you received this email in error, please
immediately delete it from your system and notify the originator. Your
cooperation is appreciated.


This message and any attachments (the "message") is
intended solely for the intended addressees and is confidential. 
If you receive this message in error,or are not the intended recipient(s), 
please delete it and any copies from your systems and immediately notify
the sender. Any unauthorized view, use that does not comply with its purpose, 
dissemination or disclosure, either whole or partial, is prohibited. Since the 
internet 
cannot guarantee the integrity of this message which may not be reliable, BNP 
PARIBAS 
(and its subsidiaries) shall not be liable for the message if modified, changed 
or falsified. 
Do not print this message unless it is necessary,consider the environment.

----------------------------------------------------------------------------------------------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le "message") 
sont etablis a l'intention exclusive de ses destinataires et sont confidentiels.
Si vous recevez ce message par erreur ou s'il ne vous est pas destine,
merci de le detruire ainsi que toute copie de votre systeme et d'en avertir
immediatement l'expediteur. Toute lecture non autorisee, toute utilisation de 
ce message qui n'est pas conforme a sa destination, toute diffusion ou toute 
publication, totale ou partielle, est interdite. L'Internet ne permettant pas 
d'assurer
l'integrite de ce message electronique susceptible d'alteration, BNP Paribas 
(et ses filiales) decline(nt) toute responsabilite au titre de ce message dans 
l'hypothese
ou il aurait ete modifie, deforme ou falsifie. 
N'imprimez ce message que si necessaire, pensez a l'environnement.

Reply via email to