Skip to content

Commit

Permalink
MODLD-602: Updated TitleFieldResponse to avoid oneOf at the top level
Browse files Browse the repository at this point in the history
  • Loading branch information
pkjacob committed Nov 22, 2024
1 parent 1eb09ea commit ddc5c83
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
{
"$ref": "../common/IdField.json"
},
{
"$ref": "title/TitleFieldResponse.json"
},
{
"type": "object",
"properties": {
"title": {
"type": "array",
"items": {
"type": "object",
"$ref": "title/TitleFieldResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/title"
},
"production": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
{
"$ref": "../common/IdField.json"
},
{
"$ref": "title/TitleFieldResponse.json"
},
{
"type": "object",
"properties": {
"title": {
"type": "array",
"items": {
"type": "object",
"$ref": "title/TitleFieldResponse.json"
},
"x-json-property": "http://bibfra.me/vocab/marc/title"
},
"targetAudience": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Title of the Work or Instance resource",
"oneOf": [
{
"type": "object",
"title": "PrimaryTitleFieldResponse",
"properties": {
"PrimaryTitle": {
"type": "object",
"$ref": "schema/resource/response/title/PrimaryTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/Title"
}
}
},
{
"type": "object",
"title": "VariantTitleFieldResponse",
"properties": {
"VariantTitle": {
"type": "object",
"$ref": "schema/resource/response/title/VariantTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/VariantTitle"
}
}
},
{
"type": "object",
"title": "ParallelTitleFieldResponse",
"properties": {
"ParallelTitle": {
"type": "object",
"$ref": "schema/resource/response/title/ParallelTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/ParallelTitle"
}
}
"properties": {
"title": {
"type": "array",
"items": {
"type": "object",
"oneOf": [
{
"type": "object",
"title": "PrimaryTitleFieldResponse",
"properties": {
"PrimaryTitle": {
"type": "object",
"$ref": "PrimaryTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/Title",
"description": "The primary title of the work or instance"
}
}
},
{
"type": "object",
"title": "VariantTitleFieldResponse",
"properties": {
"VariantTitle": {
"type": "object",
"$ref": "VariantTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/VariantTitle",
"description": "The variant title of the work or instance"
}
}
},
{
"type": "object",
"title": "ParallelTitleFieldResponse",
"properties": {
"ParallelTitle": {
"type": "object",
"$ref": "ParallelTitleResponse.json",
"x-json-property": "http://bibfra.me/vocab/marc/ParallelTitle",
"description": "The parallel title of the work or instance"
}
}
}
]
},
"x-json-property": "http://bibfra.me/vocab/marc/title"
}
]
}
}
4 changes: 2 additions & 2 deletions src/test/java/org/folio/linked/data/test/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.folio.linked.data.configuration.json.ObjectMapperConfig;
import org.folio.linked.data.domain.dto.InstanceResponseAllOfMap;
import org.folio.linked.data.domain.dto.ResourceResponseField;
import org.folio.linked.data.domain.dto.TitleFieldResponse;
import org.folio.linked.data.domain.dto.TitleFieldResponseTitleInner;
import org.folio.linked.data.exception.RequestProcessingExceptionBuilder;
import org.folio.linked.data.model.entity.Resource;
import org.folio.linked.data.test.json.InstanceResponseAllOfMapDeserializer;
Expand Down Expand Up @@ -72,7 +72,7 @@ public class TestUtil {
static {
OBJECT_MAPPER.registerModule(new SimpleModule()
.addDeserializer(ResourceResponseField.class, new ResourceResponseFieldDeserializer())
.addDeserializer(TitleFieldResponse.class, new TitleFieldResponseDeserializer())
.addDeserializer(TitleFieldResponseTitleInner.class, new TitleFieldResponseDeserializer())
.addDeserializer(InstanceResponseAllOfMap.class, new InstanceResponseAllOfMapDeserializer())
);
PARAMETERS.excludeField(named("id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
import java.util.Map;
import org.folio.linked.data.domain.dto.ParallelTitleFieldResponse;
import org.folio.linked.data.domain.dto.PrimaryTitleFieldResponse;
import org.folio.linked.data.domain.dto.TitleFieldResponse;
import org.folio.linked.data.domain.dto.TitleFieldResponseTitleInner;
import org.folio.linked.data.domain.dto.VariantTitleFieldResponse;
import org.folio.linked.data.util.DtoDeserializer;

public class TitleFieldResponseDeserializer extends JsonDeserializer<TitleFieldResponse> {
private static final Map<String, Class<? extends TitleFieldResponse>> IDENDTITY_MAP = Map.of(
public class TitleFieldResponseDeserializer extends JsonDeserializer<TitleFieldResponseTitleInner> {
private static final Map<String, Class<? extends TitleFieldResponseTitleInner>> IDENDTITY_MAP = Map.of(
TITLE.getUri(), PrimaryTitleFieldResponse.class,
PARALLEL_TITLE.getUri(), ParallelTitleFieldResponse.class,
VARIANT_TITLE.getUri(), VariantTitleFieldResponse.class
);
private final DtoDeserializer<TitleFieldResponse> dtoDeserializer =
new DtoDeserializer<>(TitleFieldResponse.class, IDENDTITY_MAP, EMPTY_EXCEPTION_BUILDER);
private final DtoDeserializer<TitleFieldResponseTitleInner> dtoDeserializer =
new DtoDeserializer<>(TitleFieldResponseTitleInner.class, IDENDTITY_MAP, EMPTY_EXCEPTION_BUILDER);

@Override
public TitleFieldResponse deserialize(JsonParser jp, DeserializationContext dc) throws IOException {
public TitleFieldResponseTitleInner deserialize(JsonParser jp, DeserializationContext dc) throws IOException {
return dtoDeserializer.deserialize(jp);
}
}

0 comments on commit ddc5c83

Please sign in to comment.