Class MarshalledList
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Object>,Collection<Object>,Deque<Object>,List<Object>,Queue<Object>
This class is the base for JsonList and the per-marshaller XList variants. It carries
all marshaller-neutral functionality such as typed accessors, fluent setters, bean integration,
and PathTraversal-based path navigation. The default AbstractCollection.toString() comes from
LinkedList; subclasses should override it to produce the appropriate marshalled form.
Note that the use of this class is optional. The serializers will accept any objects that implement the
Collection interface. But this class provides useful additional functionality when working with
data models constructed from Java Collections Framework objects.
Notes:
- This class is not thread safe.
-
Field Summary
FieldsFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty list.MarshalledList(Reader in, Parser p) Construct a list initialized by parsing the specified reader with the specified parser.MarshalledList(CharSequence in, Parser p) Construct a list initialized by parsing the specified string with the specified parser.MarshalledList(Object... entries) Construct a list initialized with the contents.MarshalledList(Collection<?> copyFrom) Construct a list initialized with the specified collection.MarshalledList(MarshallingSession session) Construct an empty list with the specified bean context. -
Method Summary
Modifier and TypeMethodDescriptionAdds the value to this list.Adds all the values in the specified array to this list.append(Collection<?> values) Adds all the values in the specified collection to this list.Adds an entry to this list if the boolean flag istrue .<T> MarshalledListAdd if predicate matches.appendReverse(Object... values) Adds the contents of the array to the list in reverse order.appendReverse(List<?> values) Adds all the entries in the specified collection to this list in reverse order.Returns the node addressed by the specified RFC 6901 JSON Pointer relative to this list.protected MarshallingSessionbs()Returns theMarshallingSessionassociated with this list (lazily defaults toMarshallingContext.DEFAULT_SESSION).static MarshalledListcreate()Construct an empty list.Similar toremove(int),but the key is a slash-delimited path used to traverse entries in this POJO.<E> Iterable<E>Creates anIterablewith elements of the specified child type.<T> TGet the entry at the specified index, converted to the specified type.<T> TGet the entry at the specified index, converted to the specified type.<T> TSame asget(int,Class), but the key is a slash-delimited path used to traverse entries in this POJO.<T> TSame asgetAt(String,Class), but allows for conversion to complex maps and collections.getBoolean(int index) Shortcut for callingget(index, Boolean..class )ClassMeta<?>getClassMeta(int index) Returns theClassMetaof the class of the object at the specified index.getInt(int index) Shortcut for callingget(index, Integer..class )getList(int index) Shortcut for callingget(index, MarshalledList..class )<E> List<E>Same asgetList(int)except converts the elements to the specified types.getLong(int index) Shortcut for callingget(index, Long..class )getMap(int index) Shortcut for callingget(index, MarshalledMap..class )<K,V> Map<K, V> Same asgetMap(int)except converts the keys and values to the specified types.Returns theMarshallingSessioncurrently associated with this list.getString(int index) Shortcut for callingget(index, String..class )booleanReturnstrue if this list is unmodifiable.Returns a modifiable copy of this list if it's unmodifiable.static MarshalledListConstruct a list initialized with the specified values.static MarshalledListof(Collection<?> values) Construct a list initialized with the specified collection.static MarshalledListConvenience method for creating a list of array objects.static MarshalledListofCollections(Collection<?>... values) Convenience method for creating a list of collection objects.static MarshalledListConstruct a list initialized by parsing the specified reader with the specified parser.static MarshalledListofString(CharSequence in, Parser p) Construct a list initialized by parsing the specified string with the specified parser.Similar toputAt(String,Object), but used to append to collections and arrays.Same asset(int,Object), but the key is a slash-delimited path used to traverse entries in this POJO.session(MarshallingSession session) Override the default bean session used for converting POJOs.setBeanSession(MarshallingSession value) Sets theMarshallingSessioncurrently associated with this list.toString(WriterSerializer serializer) Serializes this list to a string using the specified serializer.Returns an unmodifiable copy of this list if it's modifiable.Methods inherited from class java.util.LinkedList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractSequentialList
iteratorMethods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, replaceAll, retainAll, sort, subList
-
Field Details
-
EMPTY_LIST
An empty read-only MarshalledList.
-
-
Constructor Details
-
MarshalledList
public MarshalledList()Construct an empty list. -
MarshalledList
Construct an empty list with the specified bean context.- Parameters:
session- The bean session to use for creating beans.
-
MarshalledList
Construct a list initialized by parsing the specified string with the specified parser.- Parameters:
in- The input being parsed.
Can benull (results in an empty list; no parsing occurs).p- The parser to use to parse the input.
Must not benull .- Throws:
ParseException- Malformed input encountered.
-
MarshalledList
Construct a list initialized with the specified collection.- Parameters:
copyFrom- The collection to copy.
Can benull (results in an empty list).
-
MarshalledList
Construct a list initialized with the contents.- Parameters:
entries- The entries to add to this list.
-
MarshalledList
Construct a list initialized by parsing the specified reader with the specified parser.- Parameters:
in- The reader containing the input being parsed.p- The parser to use to parse the input.
Must not benull .- Throws:
ParseException- Malformed input encountered.
-
-
Method Details
-
create
Construct an empty list.- Returns:
- An empty list.
-
of
Construct a list initialized with the specified collection.- Parameters:
values- The collection to copy.
Can benull (returnsnull ).- Returns:
- A new list or
null if the input wasnull .
-
of
Construct a list initialized with the specified values.- Parameters:
values- The values to add to this list.- Returns:
- A new list, never
null .
-
ofArrays
Convenience method for creating a list of array objects.- Parameters:
values- The initial values.- Returns:
- A new list.
-
ofCollections
Convenience method for creating a list of collection objects.- Parameters:
values- The initial values.- Returns:
- A new list.
-
ofString
Construct a list initialized by parsing the specified string with the specified parser.- Parameters:
in- The input being parsed.p- The parser to use to parse the input.
Must not benull .- Returns:
- A new list (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
ofString
Construct a list initialized by parsing the specified reader with the specified parser.- Parameters:
in- The reader containing the input being parsed.p- The parser to use to parse the input.
Must not benull .- Returns:
- A new list (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
append
Adds all the values in the specified collection to this list.- Parameters:
values- The values to add to this list.- Returns:
- This object.
-
append
Adds the value to this list.- Parameters:
value- The value to add to this list.- Returns:
- This object.
-
append
Adds all the values in the specified array to this list.- Parameters:
values- The values to add to this list.- Returns:
- This object.
-
appendIf
Adds an entry to this list if the boolean flag istrue .- Parameters:
flag- The boolean flag.value- The value to add.- Returns:
- This object.
-
appendIf
Add if predicate matches.- Type Parameters:
T- The type being tested.- Parameters:
test- The predicate to match against.value- The value to add if the predicate matches.- Returns:
- This object.
-
appendReverse
Adds all the entries in the specified collection to this list in reverse order.- Parameters:
values- The collection to add to this list.- Returns:
- This object.
-
appendReverse
Adds the contents of the array to the list in reverse order.i.e. add values from the array from end-to-start order to the end of the list.
- Parameters:
values- The collection to add to this list.- Returns:
- This object.
-
at
Returns the node addressed by the specified RFC 6901 JSON Pointer relative to this list.Convenience for
MarshalledNode. . A read-miss returnsof (this ).at(pointer )null ; an addressed JSONnull value returns a null node.Beta — API subject to change: This method is part of the next-generation typed tree model layered over the
Marshalled*collections and may change incompatibly in a future release.- Parameters:
pointer- The RFC 6901 JSON Pointer.- Returns:
- A node wrapping the addressed value, or
null if the addressed value is absent.
-
toString
Serializes this list to a string using the specified serializer.- Parameters:
serializer- The serializer to use to convert this object to a string.- Returns:
- This object as a serialized string.
-
deleteAt
Similar toremove(int),but the key is a slash-delimited path used to traverse entries in this POJO.This method uses the
PathTraversalclass to perform the lookup, so the map can contain any of the various class types that thePathTraversalclass supports (e.g. beans, collections, arrays).- Parameters:
path- The path to the entry.- Returns:
- The previous value, or
null if the entry doesn't exist.
-
elements
Creates anIterablewith elements of the specified child type.Attempts to convert the child objects to the correct type if they aren't already the correct type.
The
next() method on the returned iterator may throw aInvalidDataConversionExceptionif the next element cannot be converted to the specified type.See
MarshallingSession.convertToType(Object, ClassMeta)for a description of valid conversions.- Type Parameters:
E- The child object type.- Parameters:
childType- The child object type.- Returns:
- A new
Iterable object over this list.
-
get
Get the entry at the specified index, converted to the specified type.See
MarshallingSession.convertToType(Object, ClassMeta)for the list of valid data conversions.- Type Parameters:
T- The type of object to convert the entry to.- Parameters:
index- The index into this list.type- The type of object to convert the entry to.- Returns:
- The converted entry.
-
get
Get the entry at the specified index, converted to the specified type.See
MarshallingSession.convertToType(Object, ClassMeta)for the list of valid data conversions.- Type Parameters:
T- The type of object to convert the entry to.- Parameters:
index- The index into this list.type- The type of object to convert the entry to.args- The type arguments of the type to convert the entry to.- Returns:
- The converted entry.
-
getAt
Same asget(int,Class), but the key is a slash-delimited path used to traverse entries in this POJO.- Type Parameters:
T- The class type.- Parameters:
path- The path to the entry.type- The class type.- Returns:
- The value, or
null if the entry doesn't exist.
-
getAt
Same asgetAt(String,Class), but allows for conversion to complex maps and collections.- Type Parameters:
T- The class type.- Parameters:
path- The path to the entry.type- The class type.args- The class parameter types.- Returns:
- The value, or
null if the entry doesn't exist.
-
getBoolean
Shortcut for callingget(index, Boolean..class )- Parameters:
index- The index.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException- If value cannot be converted.
-
getClassMeta
Returns theClassMetaof the class of the object at the specified index.- Parameters:
index- An index into this list, zero-based.- Returns:
- The data type of the object at the specified index, or
null if the value is null.
-
getInt
Shortcut for callingget(index, Integer..class )- Parameters:
index- The index.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException- If value cannot be converted.
-
getList
Shortcut for callingget(index, MarshalledList..class )- Parameters:
index- The index.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException- If value cannot be converted.
-
getList
Same asgetList(int)except converts the elements to the specified types.- Type Parameters:
E- The element type.- Parameters:
index- The index.elementType- The element type class.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException- If value cannot be converted.
-
getLong
Shortcut for callingget(index, Long..class )- Parameters:
index- The index.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException- If value cannot be converted.
-
getMap
Shortcut for callingget(index, MarshalledMap..class )- Parameters:
index- The index.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException- If value cannot be converted.
-
getMap
Same asgetMap(int)except converts the keys and values to the specified types.- Type Parameters:
K- The key type class.V- The value type class.- Parameters:
index- The index.keyType- The key type class.valType- The value type class.- Returns:
- The converted value.
- Throws:
InvalidDataConversionException- If value cannot be converted.
-
getMarshallingSession
Returns theMarshallingSessioncurrently associated with this list.- Returns:
- The
MarshallingSessioncurrently associated with this list.
-
getString
Shortcut for callingget(index, String..class )- Parameters:
index- The index.- Returns:
- The converted value.
-
isUnmodifiable
Returnstrue if this list is unmodifiable.- Returns:
true if this list is unmodifiable.
-
modifiable
Returns a modifiable copy of this list if it's unmodifiable.- Returns:
- A modifiable copy of this list if it's unmodifiable, or this list if it is already modifiable.
-
postAt
Similar toputAt(String,Object), but used to append to collections and arrays.This method uses the
PathTraversalclass to perform the lookup, so the map can contain any of the various class types that thePathTraversalclass supports (e.g. beans, collections, arrays).- Parameters:
path- The path to the entry.o- The new value.- Returns:
- The previous value, or
null if the entry doesn't exist.
-
putAt
Same asset(int,Object), but the key is a slash-delimited path used to traverse entries in this POJO.This method uses the
PathTraversalclass to perform the lookup, so the map can contain any of the various class types that thePathTraversalclass supports (e.g. beans, collections, arrays).- Parameters:
path- The path to the entry.o- The new value.- Returns:
- The previous value, or
null if the entry doesn't exist.
-
session
Override the default bean session used for converting POJOs.Default is
MarshallingContext.DEFAULT, which is sufficient in most cases.Useful if you're serializing/parsing beans with transforms defined.
- Parameters:
session- The new bean session.- Returns:
- This object.
-
setBeanSession
Sets theMarshallingSessioncurrently associated with this list.- Parameters:
value- TheMarshallingSessioncurrently associated with this list.- Returns:
- This object.
-
unmodifiable
Returns an unmodifiable copy of this list if it's modifiable.- Returns:
- An unmodifiable copy of this list if it's modifiable, or this list if it is already unmodifiable.
-
bs
Returns theMarshallingSessionassociated with this list (lazily defaults toMarshallingContext.DEFAULT_SESSION).- Returns:
- The
MarshallingSessionfor this list.
-