Deserialize Json Datatype File


I’m trying to deserialize a Json string to a custom class.
My json is:


externDossierNr, internDossierNr and rapport are data I get from my form.
I can deserialize externDossierNr and internDossierNr.
When I try to deserialize rapport it gives {}.
I’ve then added testarray and testword in javascript and I can read those as well.

I think the problem lies in the JsonType File.
Here I find different Json data types but File is not one of them.

I’m sending my file trough RestAngular

public save(item: any): any  {

    item["testword"] = 42;
    item["testarray"] = [2,5,9];

    console.log("item to save is ", item);
    console.log("rapport is ", item["rapport"]);

    if ( === undefined) {, item).then((addedItem: any) => {
            toastr.success(`${addedItem.naam} successfully created.`, `Overzicht Dossiers Created`);
    } else {
        this.restService.update(this.metadata.apiDomain, item).then((updatedItem: any) => {
            toastr.success(`${updatedItem.naam} successfully updated.`, `Overzicht Dossiers Updated`);

For my deserialization I used this and ([this][2] from sghill not enough rep) article

Producing the following code

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

public class DossierDeserializer extends JsonDeserializer {
    public Dossier deserialize(JsonParser jsonParser,
            DeserializationContext deserializationContext) throws IOException {
        ObjectCodec oc = jsonParser.getCodec();
        JsonNode root = oc.readTree(jsonParser);
        Dossier dossier = new Dossier();


        System.out.println("Intern Dossier nr is " + root.get("internDossierNr"));
        System.out.println("Test word " +  root.get("testword"));
        System.out.println("Test array " + root.get("testarray"));
        JsonNode node = root.get("rapport");
        if(node == null){
            System.out.println("Rapport is a null pointer.");
            System.out.println("Rapport is " + node + " with size " + node.size());
        return dossier;

Is there somewhere I can find more info on the File Json data type.
How can I send it so I can read it and deserialize it?


My assumption that was wrong that I was already printing the Json.
I was just posting the javascript object.

As for not being able to send it is because altough I have multipart/formdata in my html form upon sending it trough restangular it becomes application/json.

On this restangular issue I’ve found how to package it in Formdata.

Answered By – turoni

Answer Checked By – Marilyn (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.