A little more context:

I wrote a custom MapConverter. Below is the implementation:

public MyCustomMapConverter extends MapConverter  {

.....
        @Override
    public void marshal(Object source, HierarchicalStreamWriter writer,
            MarshallingContext context) {
        Map map = (Map)source;
        for (java.util.Iterator itor = map.entrySet().iterator();
                itor.hasNext(); ) {
            Map.Entry entry = (Map.Entry)itor.next();
            writer.startNode(entry.getKey().toString());
            writer.setValue(entry.getValue().toString());
            writer.endNode();
        }
    }
}

With this implementation, I am still unable to get XStream to add them as
"direct" values. It still drops these key/values as a part of a JSON array?

Venkatesh


On Sat, Apr 27, 2013 at 11:22 AM, Venkatesh <vvenka...@gmail.com> wrote:

> Hi !
>
> I have been using XStream to convert from Java objects to JSON and vice
> versa. I had a question and was hoping someone in this list can provide
> some help/guidance. I have a Java object that has a HashMap as a member:
>
> public class MyObject  {
>     private HashMap<String, String> myMap = new ConcurrentHashMap();
> }
>
> I am trying to use XStream to serialize this object and the serialized
> object using default XStream looks like the following:
>
> {
> "MyObject: : {
> "myMap" : [ {"@class" : "java.util.ConcurrentHashMap", "id1" : "data"} ]
>  }
> }
>
> I am looking for something like the following:
>
> "MyObject" : {
> "myMap" : {
> "id1" : "data",
> }
> }
>
> Essentially not treat the myMap object as a array and then adding the
> object type data in the "class". I was looking at the mailing list; but I
> haven't had much success. Any help would be really appreciated.
>
> Venkatesh
>
>
>

Reply via email to