com.sinch.sdk.domains.numbers.api.v1.adapters.MoneyMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sinch-sdk-java Show documentation
Show all versions of sinch-sdk-java Show documentation
SDK providing a Java API for the Sinch REST APIs.
package com.sinch.sdk.domains.numbers.api.v1.adapters;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.core.utils.databind.Mapper;
import com.sinch.sdk.domains.numbers.models.v1.Money;
import com.sinch.sdk.domains.numbers.models.v1.MoneyImpl;
import java.io.IOException;
public class MoneyMapper {
public static void initMapper() {
Mapper.getInstance().addMixIn(Money.class, MoneyMapperMixin.class);
}
private static class MoneyMapperMixin extends MoneyImpl {
@Override
@JsonSerialize(using = AmountSerializer.class)
public OptionalValue amount() {
return super.amount();
}
static class AmountSerializer extends JsonSerializer> {
public AmountSerializer() {
super();
}
@Override
public void serialize(
OptionalValue value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
if (value.isPresent()) {
jgen.writeObject(value.get().toString());
}
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy