I've solved the issue.
The json above did not correspond to the one expected and the default
constructor was missing from the MessageKey Bean.
On Friday, December 18, 2020 at 10:34:26 AM UTC+1 Meissa M'baye Sakho wrote:
> Hello everyone,
> I have marshalled an object with jackson and I'm trying unmarshall the
> generated json back to java and it does not seem to work.
> The object contains a single attribute which is a an ArrayList:
>
> *public* *class* CacheStore *implements* Serializable {
>
> *private* ArrayList<CacheItem> store;
>
> }
>
> The CacheItem has two attributes:
>
> *public class CacheItem implements Serializable {*
>
> * private PacsBean entry;*
>
> * private MessageKey key;*
>
> * }*
>
> When marshalled, the generated json output is bellow:
>
> *[ {*
>
> * "entry" : {"msgId" : "msg01","transactionId" : "001","instructionId" :
> "instr001"},*
>
> * "key" : {"id" : "id1","bicCode" : "code1"}*
>
> *},*
>
> * {*
>
> *"entry" : {"msgId" : "msg02","transactionId" : "002","instructionId" :
> "instr002"},*
>
> * "key" : {"id" : "id1","bicCode" : "code1"}*
>
> *}*
>
> * ]*
>
> When I try to unmarshall the json above, I'm expected to get a CacheStore
> with a store attribute containing the ArrayList of CacheItem.
>
> The instruction that I'm using to unmarshall the json is the following:
>
> ObjectMapper mapper = new ObjectMapper();
>
> String jsonInput = BACKUP_LOCATION_FOLDER +"cachestore.json";
>
> CacheStore cacheStore = mapper.readValue(new File(jsonInput),
> CacheStore.class);
> *I'm getting he following exception when I execute the instruction:*
> *Exception in thread "main"
> com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot
> deserialize value of type `com.redhat.consulting.jdg.model.CacheStore` from
> Array value (token `JsonToken.START_ARRAY`)*
> * at [Source: (File); line: 1, column: 1]*
> * at
> com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)*
> * at
> com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1603)*
>
> Is there something I'm missing in the instruction?
> Do I need to change the CacheStore object?
> Any input is appre
>
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jackson-user/b2c7671b-1e86-4fcc-b073-0b919ee45cf7n%40googlegroups.com.