将Base64解码为对象

时间:2017-05-29 09:22:10

标签: java spring spring-boot

我想在base64中将一个字符串解码为一个对象:

这是我解码的片段:

byte[] asBytes = Base64.getDecoder().decode("ew0KCSJ1cmwiOiAibXlVcmwub3JnL3Byb2R1Y3RzIiwNCgkibnVtIjogMTI1OTY1NA0KfQ==");

编码的字符串包含此对象:

{
    "url": "myUrl.org/products",
    "num": 1259654
} 

我需要做类似的事情:

MyObjectWrapper mObj = asByte.somthing_...

最好的问候

1 个答案:

答案 0 :(得分:1)

    com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
    String str = new String(asBytes, Charset.forName("UTF-8"));
    MyObjectWrapper mObj = mapper.readValue(str, MyObjectWrapper.class);