Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

java - Jackson how get csv and json from same object with nested field

I have a DTO with a nested object:

public class MyDto {

 private Place place;

 private Integer int1;

 private Integer int2; 
 // ... other fields, lombok getter 
}

While this is working fine if marshalled to JSON it can not be marshalled to CSV with error:

CSV generator does not support Object values for properties (nested Objects) (through reference chain: java.util.ArrayList[0]->package.MyDto["place"])

In csv i need at least some fields of place.

How to handle this without creating a new Object? Is there a Jackson way for this use case?

Is there a way to add fields (by providing getter) that are only fetched by csv and on the other hand let CSV ignore place field?

What do you suggest?

question from:https://stackoverflow.com/questions/65888945/jackson-how-get-csv-and-json-from-same-object-with-nested-field

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...