I am working on migrating entity from MongoDB to PostgreSQLand currently there is an issue when migrating field
private RentingConfiguration renting;
The Entity for MongoDB:
@Document(collection = "products")
@Getter
@Setter
@Builder
public class Product {
@Id
private String id;
// etc
private RentingConfiguration renting;
}
And the entity for PostgreSQL:
@Entity
@Table(name = "product")
@DynamicUpdate
@Jacksonized
@Getter
@Setter
@NoArgsConstructor
@SuperBuilder(buildMethodName = "buildWithoutValidation")
public class ProductMigrated {
@Id
@Column(nullable = false)
private String id;
// etc
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
private RentingConfiguration renting;
}
Here is the field looks like in the Mongo Database:
"renting": { "callToAction": "https://something.smoething.de/geld-anlegen/produkt/c81234a-7g1f-4ab1-777a-2125bt3g8bb5e", "_class": "com.my.package.product.model.renting.SowRentingConfiguration" }
The RentingConfiguration is extended by two classes:
public interface BookingConfiguration {
@JsonProperty
String type();
}
public record DocumentRenting(List<ProductLink> documentLinks) implements RentingConfiguration {
@Override
public String type() {
return "documentsAction";
}
}
public interface LinkRentingConfiguration extends RentingConfiguration {
default String type() {
return "linkAction";
}
@JsonProperty
String method();
@JsonProperty
String callToAction();
}
And the LinkRentingConfiguration is implemented by two other classes:
public record CrowddeskBookingConfiguration(String callToActionLink) implements LinkBookingConfiguration { ... }
public record EbaseBookingConfiguration(String callToActionLink, String partner) implements LinkBookingConfiguration { ... }
I have a endpoint /mongodb-to-postgresql that migrates all the products from mongodb to postgresql it calls a service that calls a mapper.
The Service calls the Mapper:
ProductMigrated product = productMapper.productToProductMigrated(product_document);
and the mapper:
@Mapper(componentModel = "spring", nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, uses = ObjectMapper.class)
public interface ProductMapper {
@Mapping(target = "breakdowns", source = "productBreakdowns")
ProductDto.ProductDtoBuilder productContentToProductDto(ProductContent content);
ProductAdminDto productToProductAdminDto(Product product);
Product productAdminDtoToProduct(ProductAdminDto productAdminDto);
ProductMigrated productAdminDtoToProductMigrated(ProductAdminDto productAdminDto);
@Mapping(source = "createdDate", target = "createdDate", qualifiedByName = "convertToOffsetDateTime")
@Mapping(source = "lastModifiedDate", target = "lastModifiedDate", qualifiedByName = "convertToOffsetDateTime")
@Mapping(source = "renting", renting= "booking", ignore = true)
ProductMigrated productToProductMigrated(Product product);
All the fields in Entities are mapped except for renting it is just null.
Any suggestions to solve this problem would be appreciated.