JsonSerialize <byte>无法使用YAML文件

时间:2019-05-07 05:26:56

标签: java json base64 yaml byte

我正在尝试在ubuntu服务器上安装Signal server 2.55,当我尝试运行config.yml时,以下配置行上的安装返回错误: 错误:私钥必须最小为32,最大为32

unidentifiedDelivery:

   expiresDays: 356
   certificate: TWFyeSBoYWQgYSBsaXR0bGUgbGFtYi4u
   privateKey: TWFyeSBoYWQgYSBsaXR0bGUgbGFtYi4=

上面的脚本在

上处理
@JsonProperty
  @JsonSerialize(using = ByteArrayAdapter.Serializing.class)
  @JsonDeserialize(using = ByteArrayAdapter.Deserializing.class)
  @NotNull
  @Size(min = 32, max = 32)
  private byte[] privateKey;

然后在此脚本上处理

public class ByteArrayAdapter {

  public static class Serializing extends JsonSerializer<byte[]> {
    @Override
    public void serialize(byte[] bytes, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException, JsonProcessingException
    {
        System.out.println("InputX:  ");
        System.out.println("Input:  "+bytes);
        System.out.println("Encode: "+Base64.encodeBytesWithoutPadding(bytes));
        jsonGenerator.writeString(Base64.encodeBytesWithoutPadding(bytes));
    }
  }

  public static class Deserializing extends JsonDeserializer<byte[]> {
    @Override
    public byte[] deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
        throws IOException, JsonProcessingException
    {
        System.out.println("Parser: "+jsonParser.getValueAsString());
        System.out.println("Decode: "+Base64.decodeWithoutPadding(jsonParser.getValueAsString()));
      return Base64.decodeWithoutPadding(jsonParser.getValueAsString());
    }
  }
}

输出为

WARNING: Please consider reporting this to the maintainers of com.fasterxml.jackson.module.afterburner.util.MyClassLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Parser: TWFyeSBoYWQgYSBsaXR0bGUgbGFtYi4=
Decode: [B@3e1162e7
io.dropwizard.configuration.ConfigurationValidationException: signal2.yml has an error:
  * unidentifiedDelivery.privateKey size must be between 32 and 32

上面输出中的

表明'void serialize'没有被系统处理。但是反序列化已处理。我认为是因为yaml文件是字符串而不是字节数组。但是我没有找到如何在YAML文件中写入字节数组的参考。 我应该在provate键上填写什么以使我的信号服务器正常工作?

0 个答案:

没有答案