共用方式為


JacksonAdapter Class

  • java.lang.Object
    • com.azure.core.util.serializer.JacksonAdapter

Implements

public class JacksonAdapter
implements SerializerAdapter

Implementation of SerializerAdapter for Jackson.

Constructor Summary

Constructor Description
JacksonAdapter()

Creates a new JacksonAdapter instance with default mapper settings.

JacksonAdapter(BiConsumer<ObjectMapper,ObjectMapper> configureSerialization)

Deprecated

This API will be removed in the future. Please use createDefaultSerializerAdapter() if you need to use JacksonAdapter.

Creates a new JacksonAdapter instance with Azure Core mapper settings and applies additional configuration through configureSerialization callback.

Method Summary

Modifier and Type Method and Description
static SerializerAdapter createDefaultSerializerAdapter()

maintain singleton instance of the default serializer adapter.

T deserialize(byte[] bytes, Type type, SerializerEncoding encoding)

Deserializes a byte array into an object.

T deserialize(HttpHeaders headers, Type deserializedHeadersType)

Deserialize the provided headers returned from a REST API to an entity instance declared as the model to hold 'Matching' headers.

T deserialize(InputStream inputStream, Type type, SerializerEncoding encoding)

Deserializes a stream into an object.

T deserialize(String value, Type type, SerializerEncoding encoding)

Deserializes a string into an object.

T deserializeHeader(Header header, Type type)

Deserializes the provided header returned from a REST API to en entity instance declared as the model of the header.

String serialize(Object object, SerializerEncoding encoding)

Serializes an object into a string.

void serialize(Object object, SerializerEncoding encoding, OutputStream outputStream)

Serializes an object and writes its output into an OutputStream.

String serializeList(List<?> list, CollectionFormat format)

Serializes a list into a string with the delimiter specified with the Swagger collection format joining each individual serialized items in the list.

com.fasterxml.jackson.databind.ObjectMapper serializer()

Deprecated

deprecated to avoid direct ObjectMapper usage in favor of using more resilient and debuggable JacksonAdapter APIs.
String serializeRaw(Object object)

Serializes an object into a raw string, leading and trailing quotes will be trimmed.

byte[] serializeToBytes(Object object, SerializerEncoding encoding)

Serializes an object into a byte array.

protected com.fasterxml.jackson.databind.ObjectMapper simpleMapper()

Deprecated

deprecated, use JacksonAdapter(BiConsumer ) constructor to configure modules.

Gets a static instance of ObjectMapper that doesn't handle flattening.

Methods inherited from java.lang.Object

Constructor Details

JacksonAdapter

public JacksonAdapter()

Creates a new JacksonAdapter instance with default mapper settings.

JacksonAdapter

@Deprecated
public JacksonAdapter(BiConsumer<ObjectMapper,ObjectMapper> configureSerialization)

Deprecated

This API will be removed in the future. Please use createDefaultSerializerAdapter() if you need to use JacksonAdapter.

Creates a new JacksonAdapter instance with Azure Core mapper settings and applies additional configuration through configureSerialization callback.

configureSerialization callback provides outer and inner instances of ObjectMapper. Both of them are pre-configured for Azure serialization needs, but only outer mapper capable of flattening and populating additionalProperties. Outer mapper is used by JacksonAdapter for all serialization needs.

Register modules on the outer instance to add custom (de)serializers similar to new JacksonAdapter((outer, inner) -> outer.registerModule(new MyModule())) Use inner mapper for chaining serialization logic in your (de)serializers.

Parameters:

configureSerialization - Applies additional configuration to outer mapper using inner mapper for module chaining.

Method Details

createDefaultSerializerAdapter

public static SerializerAdapter createDefaultSerializerAdapter()

maintain singleton instance of the default serializer adapter.

Returns:

the default serializer

deserialize

public T <T>deserialize(byte[] bytes, Type type, SerializerEncoding encoding)

Deserializes a byte array into an object.

Parameters:

bytes
type
encoding

Throws:

deserialize

public T <T>deserialize(HttpHeaders headers, Type deserializedHeadersType)

Deserialize the provided headers returned from a REST API to an entity instance declared as the model to hold 'Matching' headers.

'Matching' headers are the REST API returned headers those with:

  1. header names same as name of a properties in the entity.
  2. header names start with value of HeaderCollection annotation applied to the properties in the entity.

When needed, the 'header entity' types must be declared as first generic argument of ResponseBase<H,T> returned by java proxy method corresponding to the REST API. e.g. Mono> getMetadata(args); class FooMetadataHeaders { String name; {@literal @}HeaderCollection("header-collection-prefix-") Map headerCollection; } in the case of above example, this method produces an instance of FooMetadataHeaders from provided headers.

Parameters:

headers
deserializedHeadersType

Throws:

deserialize

public T <T>deserialize(InputStream inputStream, Type type, SerializerEncoding encoding)

Deserializes a stream into an object.

Parameters:

inputStream
type
encoding

Throws:

deserialize

public T <T>deserialize(String value, Type type, SerializerEncoding encoding)

Deserializes a string into an object.

Parameters:

value
type
encoding

Throws:

deserializeHeader

public T <T>deserializeHeader(Header header, Type type)

Deserializes the provided header returned from a REST API to en entity instance declared as the model of the header.

Parameters:

header
type

Throws:

serialize

public String serialize(Object object, SerializerEncoding encoding)

Serializes an object into a string.

Parameters:

object
encoding

Throws:

serialize

public void serialize(Object object, SerializerEncoding encoding, OutputStream outputStream)

Serializes an object and writes its output into an OutputStream.

Parameters:

object
encoding
outputStream

Throws:

serializeList

public String serializeList(List<?> list, CollectionFormat format)

Serializes a list into a string with the delimiter specified with the Swagger collection format joining each individual serialized items in the list.

Parameters:

list
format

serializer

@Deprecated
public ObjectMapper serializer()

Deprecated

deprecated to avoid direct ObjectMapper usage in favor of using more resilient and debuggable JacksonAdapter APIs.

Returns:

the original serializer type.

serializeRaw

public String serializeRaw(Object object)

Serializes an object into a raw string, leading and trailing quotes will be trimmed.

Parameters:

object

serializeToBytes

public byte[] serializeToBytes(Object object, SerializerEncoding encoding)

Serializes an object into a byte array.

Parameters:

object
encoding

Throws:

simpleMapper

@Deprecated
protected ObjectMapper simpleMapper()

Deprecated

deprecated, use JacksonAdapter(BiConsumer ) constructor to configure modules.

Gets a static instance of ObjectMapper that doesn't handle flattening.

Returns:

an instance of ObjectMapper.

Applies to