All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.co.mruoc.jsonapi.ApiDocumentDeserializer Maven / Gradle / Ivy

Go to download

Library containing jackson module and classes to help building APIs that follow the json api spec in Java

There is a newer version: 2.0.16
Show newest version
package uk.co.mruoc.jsonapi;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

import java.io.IOException;

public class ApiDocumentDeserializer extends StdDeserializer {

    private final ApiDocumentFactory documentFactory;

    public ApiDocumentDeserializer(final Class type,
                                   final ApiDocumentFactory documentFactory) {
        super(type);
        this.documentFactory = documentFactory;
    }

    @Override
    public D deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
        final JsonNode rootNode = parser.getCodec().readTree(parser);
        final JsonNode dataNode = rootNode.get("data");
        final ApiDataDocumentRequest request = ApiDataDocumentRequest.builder()
                .parser(parser)
                .context(context)
                .rootNode(rootNode)
                .dataNode(dataNode)
                .build();
        return documentFactory.build(request);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy