Class Json5List
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Object>,Collection<Object>,Deque<Object>,List<Object>,Queue<Object>
MarshalledList.
Carries the JSON5-specific surface that historically lived on JsonList: a JSON5
toString(), JSON5 default-parser constructors, and convenience methods for working with
JSON5 array text.
For strict (RFC 8259) JSON behavior, use JsonList. For a neutral, marshaller-agnostic
base with no language coupling, use MarshalledList.
Example:
Notes:
- This class is not thread safe.
-
Field Summary
FieldsFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an empty list.Construct a list initialized with the specified reader containing JSON5.Construct a list initialized with the specified reader and parser.Json5List(CharSequence json5) Construct a list initialized with the specified JSON5 text.Json5List(CharSequence in, Parser p) Construct a list initialized with the specified string.Construct a list initialized with the contents.Json5List(Collection<?> copyFrom) Construct a list initialized with the specified list.Json5List(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> Json5ListAdd 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.Converts this object into the specified class type.static Json5Listcreate()Construct an empty list.getList(int index) Shortcut for callingget(index, MarshalledList..class )getMap(int index) Shortcut for callingget(index, MarshalledMap..class )Returns a modifiable copy of this list if it's unmodifiable.static Json5ListConstruct a list initialized with the specified values.static Json5Listof(Collection<?> values) Construct a list initialized with the specified list.static Json5ListConvenience method for creating a list of array objects.static Json5ListofCollections(Collection<?>... values) Convenience method for creating a list of collection objects.static Json5ListParses a string that can consist of either a JSON5 array or comma-delimited list.static Json5ListConstruct a list initialized with the specified reader containing JSON5.static Json5ListConstruct a list initialized with the specified reader.static Json5ListofString(CharSequence json5) Construct a list initialized with the specified JSON5 string.static Json5ListofString(CharSequence in, Parser p) Construct a list initialized with the specified string.session(MarshallingSession session) Override the default bean session used for converting POJOs.setBeanSession(MarshallingSession value) Sets theMarshallingSessioncurrently associated with this list.toJson5()Serializes this list to a JSON5 string.toString()Returns an unmodifiable copy of this list if it's modifiable.Convenience method for serializing this list to the specified Writer using theJson5.DEFAULTmarshaller.Methods inherited from class org.apache.juneau.marshall.collections.MarshalledList
at, bs, deleteAt, elements, get, get, getAt, getAt, getBoolean, getClassMeta, getInt, getList, getLong, getMap, getMarshallingSession, getString, isUnmodifiable, postAt, putAt, toStringMethods 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, retainAllMethods 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 Json5List.
-
-
Constructor Details
-
Json5List
public Json5List()Construct an empty list. -
Json5List
Construct an empty list with the specified bean context.- Parameters:
session- The bean session to use for creating beans.
-
Json5List
Construct a list initialized with the specified JSON5 text.- Parameters:
json5- The JSON5 text to parse.- Throws:
ParseException- Malformed input encountered.
-
Json5List
Construct a list initialized with the specified string.- Parameters:
in- The input being parsed. Can benull or empty (results in an empty list; no parsing occurs).p- The parser to use. Ifnull , usesJson5Parser.- Throws:
ParseException- Malformed input encountered.
-
Json5List
Construct a list initialized with the specified list.- Parameters:
copyFrom- The list to copy. Can benull (results in an empty list).
-
Json5List
Construct a list initialized with the contents.- Parameters:
entries- The entries to add to this list.
-
Json5List
Construct a list initialized with the specified reader containing JSON5.- Parameters:
json5- The reader containing JSON5 text to parse.- Throws:
ParseException- Malformed input encountered.
-
Json5List
Construct a list initialized with the specified reader and parser.- Parameters:
in- The reader containing the input being parsed.p- The parser to use. Ifnull , usesJson5Parser.- Throws:
ParseException- Malformed input encountered.
-
-
Method Details
-
create
Construct an empty list.- Returns:
- An empty list.
-
of
Construct a list initialized with the specified list.- Parameters:
values- The list to copy. Can benull (returnsnull ).- Returns:
- A new list or
null if the list 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 with the specified JSON5 string.- Parameters:
json5- The JSON5 text to parse.- Returns:
- A new list (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
ofString
Construct a list initialized with the specified reader containing JSON5.- Parameters:
json5- The reader containing JSON5 text to parse.- Returns:
- A new list (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
ofJson5OrCdl
Parses a string that can consist of either a JSON5 array or comma-delimited list.The type of string is auto-detected.
- Parameters:
s- The string to parse.- Returns:
- A new list (empty if the input was
null or empty), nevernull . - Throws:
ParseException- Malformed input encountered.
-
ofString
Construct a list initialized with the specified string.- Parameters:
in- The input being parsed.p- The parser to use. Ifnull , usesJson5Parser.- Returns:
- A new list (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
ofString
Construct a list initialized with the specified reader.- Parameters:
in- The reader containing the input being parsed.p- The parser to use. Ifnull , usesJson5Parser.- Returns:
- A new list (empty if the input was
null ), nevernull . - Throws:
ParseException- Malformed input encountered.
-
append
Description copied from class:MarshalledListAdds all the values in the specified collection to this list.- Overrides:
appendin classMarshalledList- Parameters:
values- The values to add to this list.- Returns:
- This object.
-
append
Description copied from class:MarshalledListAdds the value to this list.- Overrides:
appendin classMarshalledList- Parameters:
value- The value to add to this list.- Returns:
- This object.
-
append
Description copied from class:MarshalledListAdds all the values in the specified array to this list.- Overrides:
appendin classMarshalledList- Parameters:
values- The values to add to this list.- Returns:
- This object.
-
appendIf
Description copied from class:MarshalledListAdds an entry to this list if the boolean flag istrue .- Overrides:
appendIfin classMarshalledList- Parameters:
flag- The boolean flag.value- The value to add.- Returns:
- This object.
-
appendIf
Description copied from class:MarshalledListAdd if predicate matches.- Overrides:
appendIfin classMarshalledList- 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
Description copied from class:MarshalledListAdds all the entries in the specified collection to this list in reverse order.- Overrides:
appendReversein classMarshalledList- Parameters:
values- The collection to add to this list.- Returns:
- This object.
-
appendReverse
Description copied from class:MarshalledListAdds 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.
- Overrides:
appendReversein classMarshalledList- Parameters:
values- The collection to add to this list.- Returns:
- This object.
-
cast
Converts this object into the specified class type.This method performs a round-trip serialization and deserialization to convert the list into the target type.
Notes:
- The current implementation uses a serialization round-trip which may be inefficient for frequent conversions of large objects. Consider caching results or using direct object conversion where possible.
- Parameters:
cm- The class type to convert this object to.- Returns:
- A converted object.
-
getList
Description copied from class:MarshalledListShortcut for callingget(index, MarshalledList..class )- Overrides:
getListin classMarshalledList- Parameters:
index- The index.- Returns:
- The converted value.
-
getMap
Description copied from class:MarshalledListShortcut for callingget(index, MarshalledMap..class )- Overrides:
getMapin classMarshalledList- Parameters:
index- The index.- Returns:
- The converted value.
-
modifiable
Description copied from class:MarshalledListReturns a modifiable copy of this list if it's unmodifiable.- Overrides:
modifiablein classMarshalledList- Returns:
- A modifiable copy of this list if it's unmodifiable, or this list if it is already modifiable.
-
session
Description copied from class:MarshalledListOverride 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.
- Overrides:
sessionin classMarshalledList- Parameters:
session- The new bean session.- Returns:
- This object.
-
setBeanSession
Description copied from class:MarshalledListSets theMarshallingSessioncurrently associated with this list.- Overrides:
setBeanSessionin classMarshalledList- Parameters:
value- TheMarshallingSessioncurrently associated with this list.- Returns:
- This object.
-
toJson5
Serializes this list to a JSON5 string.A synonym for
toString().- Returns:
- This object as a JSON5 string.
-
toString
- Overrides:
toStringin classAbstractCollection<Object>
-
unmodifiable
Description copied from class:MarshalledListReturns an unmodifiable copy of this list if it's modifiable.- Overrides:
unmodifiablein classMarshalledList- Returns:
- An unmodifiable copy of this list if it's modifiable, or this list if it is already unmodifiable.
-
writeTo
Convenience method for serializing this list to the specified Writer using theJson5.DEFAULTmarshaller.- Parameters:
w- The writer to send the serialized contents of this object.- Returns:
- This object.
- Throws:
IOException- If a problem occurred trying to write to the writer.SerializeException- If a problem occurred trying to convert the output.
-