Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 883921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:40:16+00:00 2026-05-15T12:40:16+00:00

I’m consuming an XML payload that looks something like this (for a more comprehensive

  • 0

I’m consuming an XML payload that looks something like this (for a more comprehensive example, check out : http://api.shopify.com/product.html ).

<products type="array">
   <product>
      ...
   </product>
   <product>
      ...
   </product>
</products>

Now currently my code does work, but its doing something that appears to be really really “wrong” – namely it associates the “products” with List.class. So the relevant code looks like the following:

    xstream.alias( "products", List.class );
    xstream.alias( "product", ShopifyProduct.class );

This is fine except when I goto externalize any object with that xstream instance it always uses “products” of course, which is not what I want.

I’d like to either be able to map generic collections to a tag:

xstream.alias( "products", ( List<ShopifyProduct> ).class ); // way too easy 

Or get the following snipet to work, which does not at the moment:

    ClassAliasingMapper mapper = new ClassAliasingMapper( xstream.getMapper( ) );
    mapper.addClassAlias( "product", ShopifyProduct.class );
    xstream.registerLocalConverter( ShopifyProductResponse.class, "products", new CollectionConverter( mapper ) );

I created the ShopifyProductResponse class to try and wrap ShopifyProduct, but its not having any of that telling me:

com.thoughtworks.xstream.mapper.CannotResolveClassException: products : products
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:68)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)

If I add:

xstream.alias( "products", List.class );

back then it goes away … so it appears to me that the mapperwrapper is not taking hold here – probably because its looking for a ShopifyProductResponse object and finding a List instead – I really don’t know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:40:16+00:00Added an answer on May 15, 2026 at 12:40 pm

    If i understand correct, this is what you are looking for.
    ShoppifyProductResponse.java

    public class ShoppifyProductResponse {
    
    private List<ShoppifyProduct> product;
    
    /**
     * @return the products
     */
    public List<ShoppifyProduct> getProducts() {
        return product;
    }
    
    /**
     * @param products
     *            the products to set
     */
    public void setProducts(List<ShoppifyProduct> products) {
        this.product = products;
    }
    

    }

    And a converter for this. UnMarshalling might look like this.

    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
        /**
         * Tune the code further..
         */
        ShoppifyProductResponse products = new ShoppifyProductResponse();
        List<ShoppifyProduct> lst = new ArrayList<ShoppifyProduct>();
        while (reader.hasMoreChildren()) {
            reader.moveDown();
            ShoppifyProduct thisProduct = (ShoppifyProduct) context.convertAnother(products,
                    ShoppifyProduct.class);
            lst.add(thisProduct);
            reader.moveUp();
        }
        products.setProducts(lst);
        return products;
    }
    

    And you can register it as,

        XStream stream = new XStream();
        stream.alias("products", ShoppifyProductResponse.class);
        stream.registerConverter(new ShoppifyConverter());
        stream.alias("product", ShoppifyProduct.class);
    

    I have tried this and it works pretty much fine. Give it a try and let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.