com.fasterxml.jackson.databind.ser.std.StdScalarSerializer Java Examples

The following examples show how to use com.fasterxml.jackson.databind.ser.std.StdScalarSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnumCustomizationFactory.java    From caravan with Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer createSerializer() {
  return new StdScalarSerializer<Enum>(Enum.class) {
    @Override
    public void serialize(Enum value, JsonGenerator gen, SerializerProvider provider) throws IOException {
      ProtobufGenerator pgen = (ProtobufGenerator) gen;

      switch (protobufConfig.getEnumMode()) {
        case ByOrdinal:
          // plus 1 to match .net
          pgen.writeNumber(value.ordinal() + 1);
          break;
        case ByValue:
          pgen.writeNumber(fetchValueOfEnum(value));
          break;
      }
    }
  };
}
 
Example #2
Source File: DecryptingObjectMapper.java    From halyard with Apache License 2.0 6 votes vote down vote up
protected StdScalarSerializer<Object> getSecretSerializer() {
  return new StdScalarSerializer<Object>(String.class, false) {
    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider)
        throws IOException {
      if (value != null) {
        String sValue = value.toString();
        if (EncryptedSecret.isEncryptedSecret(sValue)) {
          gen.writeString(secretSessionManager.decrypt(sValue));
        } else {
          gen.writeString(sValue);
        }
      }
    }
  };
}
 
Example #3
Source File: DecryptingObjectMapper.java    From halyard with Apache License 2.0 6 votes vote down vote up
protected StdScalarSerializer<Object> getSecretFileSerializer(
    BeanPropertyWriter beanPropertyWriter, SecretFile annotation, boolean shouldDecrypt) {
  return new StdScalarSerializer<Object>(String.class, false) {
    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider)
        throws IOException {
      if (value != null) {
        String sValue = value.toString();
        if (!EncryptedSecret.isEncryptedSecret(sValue) && !isURL(sValue)) {
          // metadataUrl is either a URL or a filepath, so only add prefix if it's a path
          sValue = annotation.prefix() + sValue;
        }
        if (EncryptedSecret.isEncryptedSecret(sValue) && shouldDecrypt) {
          // Decrypt the content of the file and store on the profile under a random
          // generated file name
          String name = newRandomFilePath(beanPropertyWriter.getName());
          byte[] bytes = secretSessionManager.decryptAsBytes(sValue);
          profile.getDecryptedFiles().put(name, bytes);
          sValue = annotation.prefix() + getCompleteFilePath(name);
        }
        gen.writeString(sValue);
      }
    }
  };
}
 
Example #4
Source File: BigIntegerCustomizationFactory.java    From caravan with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<BigInteger> createSerializer() {
  return new StdScalarSerializer<BigInteger>(BigInteger.class) {
    @Override
    public void serialize(BigInteger value, JsonGenerator gen, SerializerProvider provider) throws IOException {
      ProtobufGenerator pgen = (ProtobufGenerator) gen;

      // Just write. If value is bigger than Long.MAX_VALUE then the sign bit will match ulong.
      pgen.writeNumber(value.longValue());
    }
  };
}
 
Example #5
Source File: DurationCustomizationFactory.java    From caravan with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<Duration> createSerializer() {
  return new StdScalarSerializer<Duration>(Duration.class) {

    @Override
    public void serialize(Duration value, JsonGenerator gen, SerializerProvider provider) throws IOException {
      // TODO .net TimeSpan to string logic is not clear yet
      gen.writeString("1");
    }
  };
}
 
Example #6
Source File: ShortCustomizationFactory.java    From caravan with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<Short> createSerializer() {
  return new StdScalarSerializer<Short>(Short.class) {

    @Override
    public void serialize(Short value, JsonGenerator gen, SerializerProvider provider) throws IOException {
      ProtobufGenerator pgen = (ProtobufGenerator) gen;
      pgen.writeNumber((int) value);
    }
  };
}
 
Example #7
Source File: ByteCustomizationFactory.java    From caravan with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<Byte> createSerializer() {
  return new StdScalarSerializer<Byte>(Byte.class) {

    @Override
    public void serialize(Byte value, JsonGenerator gen, SerializerProvider provider) throws IOException {
      ProtobufGenerator pgen = (ProtobufGenerator) gen;
      pgen.writeNumber((int) value);
    }
  };
}
 
Example #8
Source File: BooleanCustomizationFactory.java    From caravan with Apache License 2.0 5 votes vote down vote up
@Override
public JsonSerializer<Boolean> createSerializer() {
  return new StdScalarSerializer<Boolean>(Boolean.class) {

    @Override
    public void serialize(Boolean value, JsonGenerator gen, SerializerProvider provider) throws IOException {
      ProtobufGenerator pgen = (ProtobufGenerator) gen;
      pgen.writeNumber(value ? 1 : 0);
    }
  };
}
 
Example #9
Source File: CharacterCustomizationFactory.java    From caravan with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("serial")
@Override
public JsonSerializer<Character> createSerializer() {
  return new StdScalarSerializer<Character>(Character.class) {
    @Override
    public void serialize(Character value, JsonGenerator gen, SerializerProvider provider) throws IOException {
      ProtobufGenerator pgen = (ProtobufGenerator) gen;
      pgen.writeNumber(value);
    }
  };
}
 
Example #10
Source File: PageHtmlContentRenderer.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
private static ObjectMapper createObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    final SimpleModule mod = new SimpleModule("form module");
    mod.addSerializer(Form.class, new StdScalarSerializer<Form>(Form.class){
        @Override
        public void serialize(final Form value, final JsonGenerator gen, final SerializerProvider provider) throws IOException {
            gen.writeObject(value.data());
        }
    });
    mapper.registerModule(mod);
    return mapper;
}