Package org.apache.juneau.marshall.swaps
Class BinarySwap
java.lang.Object
org.apache.juneau.marshall.swap.spi.ObjectSwap<T,String>
org.apache.juneau.marshall.swap.spi.StringSwap<byte[]>
org.apache.juneau.marshall.swaps.BinarySwap
Thin delegating swap for top-level
byte[] values in textual serializers.
Used as a fall-back swap by DefaultSwaps for root-level / map-value /
collection-element byte[] payloads that are not bean properties. Delegates to whichever
BinaryFormat is configured on the
MarshallingContext.
Disabled for:
- Binary serializers / parsers with a native byte-array wire type —
gated by
OutputStreamSerializerSession.hasNativeBytes()/InputStreamParserSession.hasNativeBytes(). Sessions that returntrue(MsgPack / CBOR / BSON) emit / consume native byte sequences and skip this swap. Sessions that returnfalse(Parquet, binary RDF) have no native byte-array primitive and still run this swap to produce / consume the configured text wire form. - CSV serializers / parsers (
CsvSerializerSession/CsvParserSession) — CSV exposes its own per-cellbyteArrayFormatsetting viaCsvByteArrayCellFormat. null-session lookups (i.e.ClassMeta-level conversion plumbing) — keeps the String-to-byte[]fallback inBasicConverter/MarshallingContext.findConversionon the simpleString.getBytes(java.nio.charset.Charset)path for non-binary inputs.
See Also:
-
Field Summary
Fields inherited from class org.apache.juneau.marshall.swap.spi.ObjectSwap
NULL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintmatch(MarshallingSession session) Returns a number indicating how well this swap matches the specified session.swap(MarshallingSession session, byte[] o) If this transform is to be used to serialize non-serializable objects, it must implement this method.byte[]unswap(MarshallingSession session, String o, ClassMeta<?> hint) If this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.Methods inherited from class org.apache.juneau.marshall.swap.spi.ObjectSwap
forMediaTypes, forMediaTypes, getNormalClass, getSwapClass, getSwapClassMeta, isNormalObject, isSwappedObject, swap, toString, unswap, withTemplate, withTemplate
-
Constructor Details
-
BinarySwap
public BinarySwap()
-
-
Method Details
-
match
Description copied from class:ObjectSwapReturns a number indicating how well this swap matches the specified session.Uses the
MediaType.match(MediaType, boolean)method algorithm to produce a number whereby a larger value indicates a "better match". The idea being that if multiple swaps are associated with a given object, we want to pick the best one.For example, if the session media type is
"text/json" , then the match values are shown below:"text/json" =100,000 "*/json" =5,100 "*/*" =5,000 - No media types specified on swap =
1 "text/xml" =0
- Overrides:
matchin classObjectSwap<byte[],String> - Parameters:
session- The bean session. Can benull (returns0 , or1 if this swap has no media types configured).- Returns:
- Zero if swap doesn't match the session, or a positive number if it does.
-
swap
Description copied from class:ObjectSwapIf this transform is to be used to serialize non-serializable objects, it must implement this method.The object must be converted into one of the following serializable types:
-
String -
Number -
Boolean -
Collectioncontaining anything on this list. -
Mapcontaining anything on this list. - A java bean with properties of anything on this list.
- An array of anything on this list.
- Overrides:
swapin classObjectSwap<byte[],String> - Parameters:
session- The bean session to use to get the class meta. This is always going to be the same bean context that created this swap.o- The object to be transformed.- Returns:
- The transformed object.
-
-
unswap
Description copied from class:ObjectSwapIf this transform is to be used to reconstitute objects that aren't true Java beans, it must implement this method.- Overrides:
unswapin classObjectSwap<byte[],String> - Parameters:
session- The bean session to use to get the class meta. This is always going to be the same bean context that created this swap.o- The transformed object.hint- If possible, the parser will try to tell you the object type being created. For example, on a serialized date, this may tell you that the object being created must be of typeGregorianCalendar.
This may benull if the parser cannot make this determination.- Returns:
- The narrowed object.
-