All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sinch.sdk.domains.numbers.api.v1.adapters.MoneyMapper Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
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