Skip to content

Commit

Permalink
Merge pull request #73 from eclipse-tractusx/feat/gate/missing-dto-de…
Browse files Browse the repository at this point in the history
…serializer

fix(gate): add missing custom JSON deserializer on DTOs
  • Loading branch information
nicoprow authored Mar 13, 2023
2 parents eb5e990 + 5b13692 commit ed91220
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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<AddressGateInputResponse>?) : StdDeserializer<AddressGateInputResponse>(vc) {
override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): AddressGateInputResponse {
val node = parser.codec.readTree<JsonNode>(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)
}
)
}
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<LegalEntityGateInputResponse>?) : StdDeserializer<LegalEntityGateInputResponse>(vc) {
override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): LegalEntityGateInputResponse {
val node = parser.codec.readTree<JsonNode>(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)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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<SiteGateInputResponse>?) : StdDeserializer<SiteGateInputResponse>(vc) {
override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): SiteGateInputResponse {
val node = parser.codec.readTree<JsonNode>(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)
}
)
}
}
)

0 comments on commit ed91220

Please sign in to comment.