public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { SortedSet sortedSet = (SortedSet) source; treeMapConverter.marshalComparator(sortedSet.comparator(), writer, context); super.marshal(source, writer, context); }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { Collection collection = (Collection) createCollection(context.getRequiredType()); populateCollection(reader, context, collection); return collection; }
protected void addCurrentElementToCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection, Collection target) { final Object item = readItem(reader, context, collection); // call readBareItem when deprecated method is removed target.add(item); }
registerConverter(new CollectionConverter(mapper), PRIORITY_NORMAL); registerConverter(new MapConverter(mapper), PRIORITY_NORMAL); registerConverter(new TreeMapConverter(mapper), PRIORITY_NORMAL);
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return ImmutableSortedSet.copyOf((List) super.unmarshal(reader, context)); }
protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection) { populateCollection(reader, context, collection, collection); }
@Override public boolean canConvert(Class type) { return super.canConvert(type) || type==CopyOnWriteArrayList.class || type==CopyOnWriteArraySet.class; }
protected void populateCollection(HierarchicalStreamReader reader, UnmarshallingContext context, Collection collection, Collection target) { while (reader.hasMoreChildren()) { reader.moveDown(); addCurrentElementToCollection(reader, context, collection, target); reader.moveUp(); } }
@Override protected void writeItem( Object item, MarshallingContext context, HierarchicalStreamWriter writer) { super.writeItem(unwrapProxies(item), context, writer); } }
ArrayList<String> stringList = new ArrayList<String>(); //example list stringList.add("abc"); //example data stringList.add("abc"); //example data stringList.add("abc"); //example data stringList.add("abc"); //example data XStream xstream = new XStream(); xstream.alias("string", String.class ); //example aliasing Mapper mapper = xstream.getMapper(); CollectionConverter aColCon = new CollectionConverter(mapper) { @Override protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer){ super.writeItem(item, context, writer); System.out.println("write object item"+item); //TODO your progress bar here! } }; xstream.registerConverter(aColCon); String asXml = xstream.toXML(stringList); System.out.println(asXml);
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { return ImmutableSet.copyOf((List) super.unmarshal(reader, context)); }
protected void populateCollection(final HierarchicalStreamReader reader, final UnmarshallingContext context, final Collection<?> collection) { populateCollection(reader, context, collection, collection); }
@Override public boolean canConvert(Class type) { if (type != null) { String typeName = type.getName(); if (typeName.equals(ARRAY_LIST) || typeName.equals(UNMODIFIABLE_LIST) || typeName.equals(UNMODIFIABLE_SET)) { return true; } } return super.canConvert(type); }
protected void populateCollection(final HierarchicalStreamReader reader, final UnmarshallingContext context, final Collection<?> collection, final Collection<?> target) { while (reader.hasMoreChildren()) { reader.moveDown(); addCurrentElementToCollection(reader, context, collection, target); reader.moveUp(); } }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Collection collection = (Collection) source; for (Iterator iterator = collection.iterator(); iterator.hasNext();) { Object item = iterator.next(); writeItem(item, context, writer); } }
public void marshal( Object source, HierarchicalStreamWriter writer, MarshallingContext context) { SortedSet sortedSet = (SortedSet) source; TreeMapConverter.marshalComparator(mapper(), sortedSet.comparator(), writer, context); super.marshal(source, writer, context); }
mapper.addClassAlias("role", String.class); xs.registerLocalConverter( ProcessGroupInfoImpl.class, "roles", new CollectionConverter(mapper)); xs.registerLocalConverter(ProcessInfoImpl.class, "roles", new CollectionConverter(mapper)); xs.registerLocalConverter( ProcessInfoImpl.class,
@Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final Class<?> collectionType = context.getRequiredType(); final Collection<?> collection = createCollection(collectionType); populateCollection(reader, context, collection); return collection; }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { // CopyOnWriteArrayList used to serialize as custom serialization, // so read it in a compatible fashion. String s = reader.getAttribute("serialization"); if(s!=null && s.equals("custom")) { return sc.unmarshal(reader,context); } else { return super.unmarshal(reader, context); } }
protected void addCurrentElementToCollection(final HierarchicalStreamReader reader, final UnmarshallingContext context, final Collection<?> collection, final Collection<?> target) { @SuppressWarnings("deprecation") final Object item = readItem(reader, context, collection); // call readBareItem when deprecated method is removed @SuppressWarnings("unchecked") final Collection<Object> targetCollection = (Collection<Object>)target; targetCollection.add(item); }