diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/AddressGateInputResponse.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/AddressGateInputResponse.kt index 87bcf92b0..94f788873 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/AddressGateInputResponse.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/AddressGateInputResponse.kt @@ -20,16 +20,13 @@ package org.eclipse.tractusx.bpdm.gate.dto import com.fasterxml.jackson.annotation.JsonUnwrapped -import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.DeserializationContext -import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.deser.std.StdDeserializer import io.swagger.v3.oas.annotations.media.Schema import org.eclipse.tractusx.bpdm.common.dto.AddressDto +import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer import java.time.LocalDateTime -@JsonDeserialize(using = AddressGateInputResponseDeserializer::class) +@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class) @Schema( name = "AddressGateInputResponse", description = "Address with legal entity or site references. " + "Only one of either legal entity or site external id can be set for an address." @@ -52,21 +49,4 @@ data class AddressGateInputResponse( @Schema(description = "Time the sharing process was started according to SaaS") val processStartedAt: LocalDateTime? = null, -) - -private class AddressGateInputResponseDeserializer(vc: Class?) : StdDeserializer(vc) { - override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): AddressGateInputResponse { - val node = parser.codec.readTree(parser) - return AddressGateInputResponse( - address = ctxt.readTreeAsValue(node, AddressDto::class.java), - externalId = node.get(AddressGateInputResponse::externalId.name).textValue(), - legalEntityExternalId = node.get(AddressGateInputResponse::legalEntityExternalId.name)?.textValue(), - siteExternalId = node.get(AddressGateInputResponse::siteExternalId.name)?.textValue(), - bpn = node.get(AddressGateInputResponse::bpn.name)?.textValue(), - processStartedAt = node.get(AddressGateInputResponse::processStartedAt.name).let { - if (it.isNull) null - else ctxt.readTreeAsValue(it, LocalDateTime::class.java) - } - ) - } -} \ No newline at end of file +) \ No newline at end of file diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/LegalEntityGateInputResponse.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/LegalEntityGateInputResponse.kt index 517c46919..556910086 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/LegalEntityGateInputResponse.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/LegalEntityGateInputResponse.kt @@ -20,16 +20,13 @@ package org.eclipse.tractusx.bpdm.gate.dto import com.fasterxml.jackson.annotation.JsonUnwrapped -import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.DeserializationContext -import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.deser.std.StdDeserializer import io.swagger.v3.oas.annotations.media.Schema import org.eclipse.tractusx.bpdm.common.dto.LegalEntityDto +import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer import java.time.LocalDateTime -@JsonDeserialize(using = LegalEntityGateInputResponseDeserializer::class) +@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class) @Schema(name = "LegalEntityGateInputResponse", description = "Legal entity with external id") data class LegalEntityGateInputResponse( @field:JsonUnwrapped @@ -44,18 +41,3 @@ data class LegalEntityGateInputResponse( @Schema(description = "Time the sharing process was started according to SaaS") val processStartedAt: LocalDateTime? = null, ) - -private class LegalEntityGateInputResponseDeserializer(vc: Class?) : StdDeserializer(vc) { - override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): LegalEntityGateInputResponse { - val node = parser.codec.readTree(parser) - return LegalEntityGateInputResponse( - legalEntity = ctxt.readTreeAsValue(node, LegalEntityDto::class.java), - externalId = node.get(LegalEntityGateInputResponse::externalId.name).textValue(), - bpn = node.get(LegalEntityGateInputResponse::bpn.name)?.textValue(), - processStartedAt = node.get(LegalEntityGateInputResponse::processStartedAt.name).let { - if (it.isNull) null - else ctxt.readTreeAsValue(it, LocalDateTime::class.java) - } - ) - } -} diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/SiteGateInputResponse.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/SiteGateInputResponse.kt index 4b5e70e26..19578dd16 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/SiteGateInputResponse.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/dto/SiteGateInputResponse.kt @@ -20,16 +20,13 @@ package org.eclipse.tractusx.bpdm.gate.dto import com.fasterxml.jackson.annotation.JsonUnwrapped -import com.fasterxml.jackson.core.JsonParser -import com.fasterxml.jackson.databind.DeserializationContext -import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.annotation.JsonDeserialize -import com.fasterxml.jackson.databind.deser.std.StdDeserializer import io.swagger.v3.oas.annotations.media.Schema import org.eclipse.tractusx.bpdm.common.dto.SiteDto +import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer import java.time.LocalDateTime -@JsonDeserialize(using = SiteGateInputResponseDeserializer::class) +@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class) @Schema( name = "SiteGateInputResponse", description = "Site with legal entity reference" ) @@ -48,20 +45,4 @@ data class SiteGateInputResponse( @Schema(description = "Time the sharing process was started according to SaaS") val processStartedAt: LocalDateTime? = null, -) - -private class SiteGateInputResponseDeserializer(vc: Class?) : StdDeserializer(vc) { - override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): SiteGateInputResponse { - val node = parser.codec.readTree(parser) - return SiteGateInputResponse( - site = ctxt.readTreeAsValue(node, SiteDto::class.java), - externalId = node.get(SiteGateInputResponse::externalId.name).textValue(), - legalEntityExternalId = node.get(SiteGateInputResponse::legalEntityExternalId.name)?.textValue()!!, - bpn = node.get(SiteGateInputResponse::bpn.name)?.textValue(), - processStartedAt = node.get(SiteGateInputResponse::processStartedAt.name).let { - if (it.isNull) null - else ctxt.readTreeAsValue(it, LocalDateTime::class.java) - } - ) - } -} \ No newline at end of file +) \ No newline at end of file