
io.github.emm035.openapi.immutables.v3.security.SecurityRequirementDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-immutables Show documentation
Show all versions of openapi-immutables Show documentation
An implementation of the OpenAPI 3.0 specification with Java Immutables
The newest version!
package io.github.emm035.openapi.immutables.v3.security;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Streams;
import java.io.IOException;
import java.util.List;
class SecurityRequirementDeserializer extends JsonDeserializer {
@Override
public SecurityRequirement deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) p.getCodec();
JsonNode node = mapper.readTree(p);
String name = node.fieldNames().next();
List scopes = Streams.stream(((ArrayNode) node.get(name)).iterator())
.map(JsonNode::asText)
.collect(ImmutableList.toImmutableList());
return SecurityRequirement.builder()
.setName(name)
.setScopes(scopes)
.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy