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

Clarify DataBase JSon type to Object #18

Open
axel3rd opened this issue Dec 23, 2020 · 0 comments
Open

Clarify DataBase JSon type to Object #18

axel3rd opened this issue Dec 23, 2020 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@axel3rd
Copy link
Owner

axel3rd commented Dec 23, 2020

Context: Some data are stored with json type in database (Table: grand_slam_day, field: players).

INSERT INTO `grand_slam_day` (`id`, `grand_slam_id`, `day`, `label`, `players`) VALUES
(77, 9, 1, 'J0 : L2j0 L1j0 PLj0', '[{"pos": 9, "pts": 0, "diff": 0, "player": 73}, {"pos": 9, "pts": 0, "diff": 0, "player": 74}, {"pos": 9, "pts": 0, "diff": 0, "player": 75}, {"pos": 9, "pts": 0, "diff": 0, "player": 76}, {"pos": 9, "pts": 0, "diff": 0, "player": 77}, {"pos": 9, "pts": 0, "diff": 0, "player": 78}, {"pos": 9, "pts": 0, "diff": 0, "player": 79}, {"pos": 9, "pts": 0, "diff": 0, "player": 80}]'),

A conversion is needed to map that in a representative Object:

@Convert(converter = PlayerDayJsonConverter.class)
private List<PlayerDayJson> players;

I don't understand why this "double" mapper usage is mandatory here, seems strange:

public List<PlayerDayJson> convertToEntityAttribute(String json) {
try {
// TODO: Why this kind of mapper ??? To understand
String s = json;
if (s.startsWith("\"")) {
s = mapper.readValue(s, String.class);
}
return mapper.readValue(s, new TypeReference<List<PlayerDayJson>>() {
});

The unit test DataBaseUpdateGrandSlamDaysTaskletTest is useful for execute this part of code.

@litteautr : If you have any idea (perhaps you have already implemented this use case), many thanks 😘.

@axel3rd axel3rd added help wanted Extra attention is needed enhancement New feature or request labels Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant