Reputation: 395
I would like to decode in base64 a string to an object:
this is a snippet how I decode:
byte[] asBytes = Base64.getDecoder().decode("ew0KCSJ1cmwiOiAibXlVcmwub3JnL3Byb2R1Y3RzIiwNCgkibnVtIjogMTI1OTY1NA0KfQ==");
the encoded string contain this object:
{
"url": "myUrl.org/products",
"num": 1259654
}
I need to do something like that:
MyObjectWrapper mObj = asByte.somthing_...
best regards
Upvotes: 0
Views: 7948
Reputation: 57411
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);
Upvotes: 3