9

We are using Coda Hale metrics in our application, with the Json module add-on to improve the JSON output of some REST services exposing the application metrics.

Recently, we started saving the metrics to MongoDB. As we are using spring-data-mongodb, the code to save POJOs is greatly simplified. Spring's MongoDB type mapping uses the usual approach (introspection of the bean properties to figure out what to save and read), however this does not play well with Code Hale objects (Timer, Counter, etc).

If we could make Spring use the JSON module already available for Jackson, that would be great, as we would be having the save serialization style and little code to maintain.

However after reading the docs and browsing some Spring mongodb source files, I can't find a straightforward to inject a custom Jackson serializing. It seems that the only way to customize the process is creating a custom MongoTypeMapper.

Does anyone know if we can inject a custom Jackson mapper, or can recommend an alternative solution?

Thanks

Stennie
  • 63,885
  • 14
  • 149
  • 175
Sebastian
  • 1,835
  • 3
  • 22
  • 34
  • Will this help? http://stackoverflow.com/questions/7854030/configurating-objectmapper-in-spring – ecbrodie Mar 20 '14 at 04:17
  • Are you interested in changing the mapping when storing to mongodb, or when serving up the objects via RESTful apis? – DavidA May 16 '14 at 17:16
  • @ecbrodie Thanks, but that doesn't explain how to inject the mapper to spring-data, just to the MVC framework (unless I got the answer wrong...) – Sebastian Jul 18 '14 at 16:06
  • @DavidA: the first think you mentioned. Thanks – Sebastian Jul 18 '14 at 16:07
  • 5
    @Sebastian Unfortunately, I do not think you can simply inject a jackson mapper as spring-data-mongo doesn't use jackson to convert to json. It actually maps directly to MongoDb DBOject instances. However, you could theoretically replace the standard MappingMongoConverter with your own implementation which uses jackson to generate the json to be written. – DavidA Jul 21 '14 at 16:47

1 Answers1

0

In the spring-data-mongodb there is section for the type mapping: link I think you can use it.

igreenfield
  • 1,618
  • 19
  • 36