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

PrettyPrint flag concerning JSON output #197

Closed
igler opened this issue Sep 14, 2015 · 6 comments
Closed

PrettyPrint flag concerning JSON output #197

igler opened this issue Sep 14, 2015 · 6 comments
Assignees

Comments

@igler
Copy link

@igler igler commented Sep 14, 2015

Add configuration option to give user a choice on pretty print or standard.

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Sep 21, 2015

released in v 1.3.8

@igler
Copy link
Author

@igler igler commented Sep 21, 2015

Do you have an example how to set this flag or is it documented somewhere?

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Sep 21, 2015

@igler
Copy link
Author

@igler igler commented Sep 21, 2015

Thanx, upgraded to the new version and testet it:

@Bean
public Javers javers() {
    JaversSqlRepository sqlRepository = SqlRepositoryBuilder
                .sqlRepository()
                .withConnectionProvider(jpaConnectionProvider())
                .withDialect(DialectName.MYSQL)
                .build();
    return TransactionalJaversBuilder
                .javers()
                .withPrettyPrint(false)
                .withObjectAccessHook(new HibernateUnproxyObjectAccessHook())
                .registerJaversRepository(sqlRepository)
                .registerValueTypeAdapter(new ZonedDateTimeJaversTypeAdapter())
                .build();
}

Now the returned string looks like:

"[{\"changeType\":\"ValueChange\",\"globalId\":{\"entity\":\"...

As the return-type in the controller is ResponseEntity<String> getChangesOfLocation(@PathVariable("id") Location location) this is probably OK. But what I'd like to have is a well structured output I normally get when I would use ResponseEntity<List<Change>> getChangesOfLocation(@PathVariable("id") Location location) . The error I get with the ResponseEntity<List<Change>> signature is something like:

Could not write content: AFFECTED_CDO_IS_NOT_AVAILABLE JaVers runtime error - affected cdo is not available, you can access it only for freshly generated diffs (through reference chain: java.util.ArrayList[0]->org.javers.core.diff.changetype.ValueChange[\"affectedCdo\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: AFFECTED_CDO_IS_NOT_AVAILABLE JaVers runtime error - affected cdo is not available, you can access it only for freshly generated diffs (through reference chain: java.util.ArrayList[0]->org.javers.core.diff.changetype.ValueChange[\"affectedCdo\"])",
  "path": "/api/locations/17/changes"

Doing a debug-session I can see that the affectedCdo variable is null Any chance to inject the codId into the Change object before sending it to the ResponseEntity serialization through Spring/Jackson?.

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Sep 21, 2015

well, so the root cause is, that Jackson cant serialize JaVers Changes to JSON.
I've never tested JaVers with Jackson, we are using Gson but we want Javers to be compatible with spring-mvc, so it do have sense to make JaVers objects beeing Jackson friendly.

I'd prefer if you put a separate issue for that, sth like 'JaVers objects (Change, CdoSnapshot) should be Jackson friendly'.

Now I'm working on backlog for upcoming releases, think that new issue should have high priority ...

@igler
Copy link
Author

@igler igler commented Sep 22, 2015

OK, opened #205 to continue discussion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.