Search in sources :

Example 11 with Decoder

use of io.micronaut.serde.Decoder in project micronaut-serialization by micronaut-projects.

the class DefaultSerdeRegistry method registerPrimitiveSerdes.

private void registerPrimitiveSerdes() {
    this.deserializerMap.put(new TypeKey(Argument.BOOLEAN), (decoder, decoderContext, type) -> decoder.decodeBoolean());
    this.deserializerMap.put(new TypeKey(Argument.of(Boolean.class)), (NullableDeserializer<Boolean>) (decoder, decoderContext, type) -> decoder.decodeBoolean());
    this.deserializerMap.put(new TypeKey(Argument.CHAR), (decoder, decoderContext, type) -> decoder.decodeChar());
    this.deserializerMap.put(new TypeKey(Argument.of(Character.class)), (NullableDeserializer<Character>) (decoder, decoderContext, type) -> decoder.decodeChar());
}
Also used : OrderUtil(io.micronaut.core.order.OrderUtil) Arrays(java.util.Arrays) ObjectDeserializer(io.micronaut.serde.support.deserializers.ObjectDeserializer) BeanContext(io.micronaut.context.BeanContext) URL(java.net.URL) ArrayUtils(io.micronaut.core.util.ArrayUtils) SerdeRegistry(io.micronaut.serde.SerdeRegistry) BigDecimal(java.math.BigDecimal) Locale(java.util.Locale) Map(java.util.Map) SerdeIntrospections(io.micronaut.serde.SerdeIntrospections) BigInteger(java.math.BigInteger) URI(java.net.URI) TimeZone(java.util.TimeZone) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Singleton(jakarta.inject.Singleton) PropertyNamingStrategy(io.micronaut.serde.config.naming.PropertyNamingStrategy) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) StringUtils(io.micronaut.core.util.StringUtils) List(java.util.List) Stream(java.util.stream.Stream) Decoder(io.micronaut.serde.Decoder) BeanRegistration(io.micronaut.context.BeanRegistration) ObjectSerializer(io.micronaut.serde.support.serializers.ObjectSerializer) OptionalDouble(java.util.OptionalDouble) TypeKey(io.micronaut.serde.support.util.TypeKey) HashMap(java.util.HashMap) Encoder(io.micronaut.serde.Encoder) Deserializer(io.micronaut.serde.Deserializer) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) Serializer(io.micronaut.serde.Serializer) Charset(java.nio.charset.Charset) Nullable(io.micronaut.core.annotation.Nullable) Secondary(io.micronaut.context.annotation.Secondary) Argument(io.micronaut.core.type.Argument) NumberSerde(io.micronaut.serde.support.serdes.NumberSerde) ConfigurationException(io.micronaut.context.exceptions.ConfigurationException) Iterator(java.util.Iterator) NullableDeserializer(io.micronaut.serde.util.NullableDeserializer) IOException(java.io.IOException) ReflectionUtils(io.micronaut.core.reflect.ReflectionUtils) NonNull(io.micronaut.core.annotation.NonNull) Serde(io.micronaut.serde.Serde) CollectionUtils(io.micronaut.core.util.CollectionUtils) BeanIntrospection(io.micronaut.core.beans.BeanIntrospection) BeanDefinition(io.micronaut.inject.BeanDefinition) Collections(java.util.Collections) Order(io.micronaut.core.annotation.Order) SerdeException(io.micronaut.serde.exceptions.SerdeException) NullableSerde(io.micronaut.serde.util.NullableSerde) TypeKey(io.micronaut.serde.support.util.TypeKey)

Example 12 with Decoder

use of io.micronaut.serde.Decoder in project micronaut-serialization by micronaut-projects.

the class DefaultSerdeRegistry method registerBuiltInSerdes.

private void registerBuiltInSerdes() {
    this.deserializerMap.put(new TypeKey(Argument.STRING), (NullableDeserializer<String>) (decoder, decoderContext, type) -> decoder.decodeString());
    Stream.of(new IntegerSerde(), new LongSerde(), new ShortSerde(), new FloatSerde(), new ByteSerde(), new DoubleSerde(), new OptionalIntSerde(), new OptionalDoubleSerde(), new OptionalLongSerde(), new BigDecimalSerde(), new BigIntegerSerde(), new UUIDSerde(), new URLSerde(), new URISerde(), new CharsetSerde(), new TimeZoneSerde(), new LocaleSerde(), new IntArraySerde(), new LongArraySerde(), new FloatArraySerde(), new ShortArraySerde(), new DoubleArraySerde(), new BooleanArraySerde(), new ByteArraySerde(), new CharArraySerde()).forEach(this::register);
}
Also used : OrderUtil(io.micronaut.core.order.OrderUtil) Arrays(java.util.Arrays) ObjectDeserializer(io.micronaut.serde.support.deserializers.ObjectDeserializer) BeanContext(io.micronaut.context.BeanContext) URL(java.net.URL) ArrayUtils(io.micronaut.core.util.ArrayUtils) SerdeRegistry(io.micronaut.serde.SerdeRegistry) BigDecimal(java.math.BigDecimal) Locale(java.util.Locale) Map(java.util.Map) SerdeIntrospections(io.micronaut.serde.SerdeIntrospections) BigInteger(java.math.BigInteger) URI(java.net.URI) TimeZone(java.util.TimeZone) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Singleton(jakarta.inject.Singleton) PropertyNamingStrategy(io.micronaut.serde.config.naming.PropertyNamingStrategy) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) StringUtils(io.micronaut.core.util.StringUtils) List(java.util.List) Stream(java.util.stream.Stream) Decoder(io.micronaut.serde.Decoder) BeanRegistration(io.micronaut.context.BeanRegistration) ObjectSerializer(io.micronaut.serde.support.serializers.ObjectSerializer) OptionalDouble(java.util.OptionalDouble) TypeKey(io.micronaut.serde.support.util.TypeKey) HashMap(java.util.HashMap) Encoder(io.micronaut.serde.Encoder) Deserializer(io.micronaut.serde.Deserializer) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) OptionalLong(java.util.OptionalLong) Serializer(io.micronaut.serde.Serializer) Charset(java.nio.charset.Charset) Nullable(io.micronaut.core.annotation.Nullable) Secondary(io.micronaut.context.annotation.Secondary) Argument(io.micronaut.core.type.Argument) NumberSerde(io.micronaut.serde.support.serdes.NumberSerde) ConfigurationException(io.micronaut.context.exceptions.ConfigurationException) Iterator(java.util.Iterator) NullableDeserializer(io.micronaut.serde.util.NullableDeserializer) IOException(java.io.IOException) ReflectionUtils(io.micronaut.core.reflect.ReflectionUtils) NonNull(io.micronaut.core.annotation.NonNull) Serde(io.micronaut.serde.Serde) CollectionUtils(io.micronaut.core.util.CollectionUtils) BeanIntrospection(io.micronaut.core.beans.BeanIntrospection) BeanDefinition(io.micronaut.inject.BeanDefinition) Collections(java.util.Collections) Order(io.micronaut.core.annotation.Order) SerdeException(io.micronaut.serde.exceptions.SerdeException) NullableSerde(io.micronaut.serde.util.NullableSerde) TypeKey(io.micronaut.serde.support.util.TypeKey)

Example 13 with Decoder

use of io.micronaut.serde.Decoder in project micronaut-serialization by micronaut-projects.

the class EnumSetDeserializer method deserialize.

@Override
public EnumSet<E> deserialize(Decoder decoder, DecoderContext context, Argument<? super EnumSet<E>> type) throws IOException {
    final Argument[] generics = type.getTypeParameters();
    if (ArrayUtils.isEmpty(generics)) {
        throw new SerdeException("Cannot deserialize raw list");
    }
    @SuppressWarnings("unchecked") final Argument<E> generic = (Argument<E>) generics[0];
    final Decoder arrayDecoder = decoder.decodeArray();
    HashSet<E> set = new HashSet<>();
    while (arrayDecoder.hasNextArrayValue()) {
        set.add(Enum.valueOf(generic.getType(), arrayDecoder.decodeString()));
    }
    arrayDecoder.finishStructure();
    return EnumSet.copyOf(set);
}
Also used : Argument(io.micronaut.core.type.Argument) SerdeException(io.micronaut.serde.exceptions.SerdeException) Decoder(io.micronaut.serde.Decoder) HashSet(java.util.HashSet)

Aggregations

Decoder (io.micronaut.serde.Decoder)13 Argument (io.micronaut.core.type.Argument)6 Deserializer (io.micronaut.serde.Deserializer)5 SerdeException (io.micronaut.serde.exceptions.SerdeException)5 BeanIntrospection (io.micronaut.core.beans.BeanIntrospection)3 PropertyNamingStrategy (io.micronaut.serde.config.naming.PropertyNamingStrategy)3 IOException (java.io.IOException)3 Collection (java.util.Collection)3 BeanContext (io.micronaut.context.BeanContext)2 BeanRegistration (io.micronaut.context.BeanRegistration)2 Secondary (io.micronaut.context.annotation.Secondary)2 ConfigurationException (io.micronaut.context.exceptions.ConfigurationException)2 NonNull (io.micronaut.core.annotation.NonNull)2 Nullable (io.micronaut.core.annotation.Nullable)2 Order (io.micronaut.core.annotation.Order)2 OrderUtil (io.micronaut.core.order.OrderUtil)2 ReflectionUtils (io.micronaut.core.reflect.ReflectionUtils)2 ArrayUtils (io.micronaut.core.util.ArrayUtils)2 CollectionUtils (io.micronaut.core.util.CollectionUtils)2 StringUtils (io.micronaut.core.util.StringUtils)2