Class SerializerSet
Serializers that can be looked up by media type.
Description
Provides the following features:-
Finds serializers based on HTTP
Accept header values. - Sets common properties on all serializers in a single method call.
- Clones existing groups and all serializers within the group in a single method call.
Match ordering
Serializers are matched againstAdding new entries will cause the entries to be prepended to the group. This allows for previous serializers to be overridden through subsequent calls.
For example, calling g.append(S1.
will result in the order
Example:
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static classAn identifier that the previous entries in this group should be inherited.static classAn identifier that the previous entries in this group should not be inherited. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSerializerSet(SerializerSet.Builder builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates a copy of this serializer group.static SerializerSet.Buildercreate()Static creator.static SerializerSet.BuilderStatic creator.getSerializer(String acceptHeader) Same asgetSerializerMatch(String)but returns just the matched serializer.getSerializer(MediaType mediaType) Same asgetSerializerMatch(MediaType)but returns just the matched serializer.getSerializerMatch(String acceptHeader) Searches the group for a serializer that can handle the specifiedAccept value.getSerializerMatch(MediaType mediaType) Same asgetSerializerMatch(String)but matches using aMediaTypeinstance.Returns a copy of the serializers in this group.getStreamSerializer(String acceptHeader) Same asgetSerializer(String), but casts it to anOutputStreamSerializer.getStreamSerializer(MediaType mediaType) Same asgetSerializer(MediaType), but casts it to aOutputStreamSerializer.Returns the media types that all serializers in this group can handle.getWriterSerializer(String acceptHeader) Same asgetSerializer(String), but casts it to aWriterSerializer.getWriterSerializer(MediaType mediaType) Same asgetSerializer(MediaType), but casts it to aWriterSerializer.booleanisEmpty()Returnstrue if this group contains no serializers.
-
Constructor Details
-
SerializerSet
Constructor.- Parameters:
builder- The builder for this bean.
-
-
Method Details
-
create
Static creator.- Returns:
- A new builder for this object.
-
create
Static creator.- Parameters:
beanStore- The bean store to use for creating beans.- Returns:
- A new builder for this object.
-
copy
Creates a copy of this serializer group.- Returns:
- A new copy of this serializer group.
-
getSerializer
Same asgetSerializerMatch(MediaType)but returns just the matched serializer.- Parameters:
mediaType- The HTTP media type.- Returns:
- The serializer that matched the accept header, or
null if no match was made.
-
getSerializer
Same asgetSerializerMatch(String)but returns just the matched serializer.- Parameters:
acceptHeader- The HTTPAccept header string.- Returns:
- The serializer that matched the accept header, or
null if no match was made.
-
getSerializerMatch
Same asgetSerializerMatch(String)but matches using aMediaTypeinstance.- Parameters:
mediaType- The HTTP media type.- Returns:
- The serializer and media type that matched the media type, or
null if no match was made.
-
getSerializerMatch
Searches the group for a serializer that can handle the specifiedAccept value.The
accept value complies with the syntax described in RFC2616, Section 14.1, as described below:Accept = "Accept" ":" #( media-range [ accept-params ] ) media-range = ( "*\/*" | ( type "/" "*" ) | ( type "/" subtype ) ) *( ";" parameter ) accept-params = ";" "q" "=" qvalue *( accept-extension ) accept-extension = ";" token [ "=" ( token | quoted-string ) ]
The returned object includes both the serializer and media type that matched.
- Parameters:
acceptHeader- The HTTPAccept header string.- Returns:
- The serializer and media type that matched the accept header, or
null if no match was made.
-
getSerializers
Returns a copy of the serializers in this group.- Returns:
- An unmodifiable list of serializers in this group.
-
getStreamSerializer
Same asgetSerializer(MediaType), but casts it to aOutputStreamSerializer.- Parameters:
mediaType- The HTTP media type.- Returns:
- The serializer that matched the accept header, or
null if no match was made.
-
getStreamSerializer
Same asgetSerializer(String), but casts it to anOutputStreamSerializer.- Parameters:
acceptHeader- The HTTPAccept header string.- Returns:
- The serializer that matched the accept header, or
null if no match was made.
-
getSupportedMediaTypes
Returns the media types that all serializers in this group can handle.Entries are ordered in the same order as the serializers in the group.
- Returns:
- An unmodifiable list of media types.
-
getWriterSerializer
Same asgetSerializer(MediaType), but casts it to aWriterSerializer.- Parameters:
mediaType- The HTTP media type.- Returns:
- The serializer that matched the accept header, or
null if no match was made.
-
getWriterSerializer
Same asgetSerializer(String), but casts it to aWriterSerializer.- Parameters:
acceptHeader- The HTTPAccept header string.- Returns:
- The serializer that matched the accept header, or
null if no match was made.
-
isEmpty
Returnstrue if this group contains no serializers.- Returns:
true if this group contains no serializers.
-