Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gate): add missing custom JSON deserializer on DTOs #73

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
)
}
}
)