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());
}
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);
}
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);
}
Aggregations