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

Provide ready to use json serializer(something based on jackson) #13

Closed
nikolavp opened this issue Aug 15, 2014 · 2 comments · Fixed by #17
Closed

Provide ready to use json serializer(something based on jackson) #13

nikolavp opened this issue Aug 15, 2014 · 2 comments · Fixed by #17
Assignees
Milestone

Comments

@nikolavp
Copy link
Owner

This should be included as a submodule:

  1. Move the current main project as a submodule named approval-core
  2. Create approval-json submodule that contains the json converter implementation
@powerslider
Copy link

public class JacksonJsonConverter<T> extends AbstractStringConverter<T>  {
    private ObjectMapper mapper = new ObjectMapper()
            .enable(SerializationFeature.INDENT_OUTPUT)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

    @Nonnull
    @Override
    protected String getStringForm(T entity) {
        try {
            return mapper.writeValueAsString(entity);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("Could not convert " + entity.getClass() + "object", e);
        }
    }
}

@powerslider
Copy link

I think that this converter is more beneficial because it can recursively serialize any other entities within your current one. For example:

class Foo {
    private String name;
    private Bar bar;
}
class Bar {
   private String name;
   private String color;
}

As a result if you convert Foo your serialiazed format would look like this:

{
  "name" : null,
  "bar" : {
         "name" : null,
         "color" : null
  }
}

@nikolavp nikolavp added this to the Approval 0.3 milestone Aug 20, 2014
@nikolavp nikolavp added the ready label Aug 21, 2014
@nikolavp nikolavp self-assigned this Aug 21, 2014
nikolavp added a commit that referenced this issue Sep 1, 2014
Reorganization for modules so the jackson converter doesn't add a hard
dependency on jackson for the whole approval project.

Closes #13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants