Skip to content

Tag: spring

How to serialize nested ObjectId to String with Jackson?

There are many questions concerning conversion from ObjectId to String with jackson. All answers suggest either creating own JsonSerializer<ObjectId> or annotating the ObjectId field with @JsonSerialize(using = ToStringSerializer.class). However, I have a map that sometimes contains ObjectIds, i.e.: I want jackson to convert it to: But I get: I have registered the conversion (in Spring) with And the first-level ObjectIds

Using spring converter in @RequestBody

Is it possible to enforce Converter ( org.springframework.core.convert.converter.Converter) to finish json object mapping? Json code example: where somename – string, id – integer value mapping to : Converter code example: What I want to achieve is to map that json to the object which will have automatically fetched from db nested object. Answer You should implement your own JacksonCustomMapper, by

Maven spring boot run debug with arguments

Usually I’m running my Spring Boot application with command: I want to set custom port to debug, so I can connect from eclipse. When I add arguments from example it works but other arguments like server.port or are no longer recognized and I get exception like: Question: How I can run with all arguments? Answer The behavior and

Overriding beans in Integration tests

For my Spring-Boot app I provide a RestTemplate though a @Configuration file so I can add sensible defaults(ex Timeouts). For my integration tests I would like to mock the RestTemplate as I dont want to connect to external services – I know what responses to expect. I tried providing a different implementation in the integration-test package in the hope that

Spring Data MongoDB Annotation @CreatedDate isn’t working, when ID is assigned manually

I’m trying to use auditing to save dateCreated and dateUpdated in my objects, but since I set ID manually, there’s some additional work. Following Oliver Gierke’s suggestion in DATAMONGO-946 I’m trying to figure out how to correctly implement it. As original poster in Jira task above, I’ve downloaded example from here and modified it a bit: and and a

validation with double value in Spring

I want to check score which have value: 0.00 <= value<= 10.00 I used: -Model(Score): -servlet-context.xml: But the value = 10.01 has passed the check. Please help me. Answer I resolve my proplem with: Thank you lots @ Kayaman ,@hyness

What will happen if we interchange @service and @repository annotation in the spring MVC

Why we needs to use @service inside the service Implementation and @repository in the DAO Implementation. There are no problem occur when I interchange the @service and @repository annotation in the spring MVC. Answer According to documentaion @Repository,@Service,@Controller are all synonyms. They all are just specializations of @Component annotation. So, generally, they can be used one instead of other. But