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

Object Mapping error #4646

Closed
myob-hankun opened this issue Feb 20, 2024 · 2 comments
Closed

Object Mapping error #4646

myob-hankun opened this issue Feb 20, 2024 · 2 comments
Assignees
Labels
status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged

Comments

@myob-hankun
Copy link

myob-hankun commented Feb 20, 2024

Hi Team,
I upgraded springboot to 3. spring-boot-starter-data-mongodb to 3.2.2. jdk to 21. And mongo is 5. So I think there is no problem with compatibility I have some errors.

And I have a java object

@Data
@Document
@Accessors(chain = true)
public class PublishedReportPack {
    @Id
    public String id;
    private Map<String, PublishedReportPackReport> reports;
}

PublishedReportPackReport is

@Data
@Accessors(chain = true)
public class PublishedReportPackReport {
    private ChartCollection charts;
    private String status;
}

ChartCollection is a basic class. it has a child class

@Accessors(chain = true)
@Data
@Document
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@JsonIdentifyingField("revenueSummary")
public class SalesCollection extends ChartCollection {
   private ChartDTO<List<LineChartDTO>> ytdRevenue;
}

TopRevenueContributingItemDTO is

@Data
@Accessors(chain = true)
public class TopRevenueContributingItemDTO {
    private BigDecimal percentageOfTotal;
    private int rank;
}

ChartDTO is

@Data
@Accessors(chain = true)
public class ChartDTO<T> {
    private T series;
    private List<String> label = new ArrayList<>();
}

LineChartDTO is

public class LineChartDTO {
    private String name;
    private List<Double> data;
}

Currently, when I use findAllById(), it has an error.
org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.math.BigDecimal] for value [Food]

The Food is the name field of the LineChartDTO class.
TopRevenueContributingItemDTO also has this error.

I think it should be of string type directly, but Mongo wants to map Food to BigDecimal, and the name field is defined as String instead of BigDecimal. Why does this happen?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 20, 2024
@mp911de
Copy link
Member

mp911de commented Feb 20, 2024

We have a hard time following what is happening here. Please provide a minimal reproducer or at least the MongoDB document as JSON so that we can understand the initial setup.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Feb 20, 2024
@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 20, 2024
@christophstrobl
Copy link
Member

Thank you @myob-hankun for the json. However there are still some bits (like the ChartCollection or TableDTO) missing.
If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

@christophstrobl christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants