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

io.github.stewseo.client.transport.endpoints.EndpointWithResponseMapperAttr Maven / Gradle / Ivy

Go to download

java client to build api objects, handle http transport, and parse/deserialize/serialize json to/from json

There is a newer version: 1.8.0
Show newest version
package io.github.stewseo.client.transport.endpoints;

import io.github.stewseo.client.json.DelegatingDeserializer;
import io.github.stewseo.client.json.JsonpDeserializer;
import io.github.stewseo.client.json.JsonpMapper;
import io.github.stewseo.client.transport.JsonEndpoint;
import jakarta.json.stream.JsonParser;


public class EndpointWithResponseMapperAttr extends DelegatingJsonEndpoint {

    private final String attrName;
    private final Object attrValue;

    public EndpointWithResponseMapperAttr(JsonEndpoint endpoint, String attrName, Object attrValue) {
        super(endpoint);
        this.attrName = attrName;
        this.attrValue = attrValue;
    }
    
    @Override
    public JsonpDeserializer responseDeserializer() {
        return new DelegatingDeserializer.SameType<>() {
            @Override
            protected JsonpDeserializer unwrap() {
                return endpoint.responseDeserializer();
            }

            @Override
            public Res deserialize(JsonParser parser, JsonpMapper mapper) {
                mapper = mapper.withAttribute(attrName, attrValue);
                return super.deserialize(parser, mapper);
            }

            @Override
            public Res deserialize(JsonParser parser, JsonpMapper mapper, JsonParser.Event event) {
                mapper = mapper.withAttribute(attrName, attrValue);
                return super.deserialize(parser, mapper, event);
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy