io.github.stewseo.client.transport.endpoints.EndpointWithResponseMapperAttr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yelp-fusion-client Show documentation
Show all versions of yelp-fusion-client Show documentation
java client to build api objects, handle http transport, and parse/deserialize/serialize json to/from json
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