spring-cloud / spring-cloud-bus

Spring Cloud event bus
http://cloud.spring.io/spring-cloud-bus/
Apache License 2.0
409 stars 242 forks source link

Port forcing dates as timestamps to 1.3.x #200

Closed leason805 closed 4 years ago

leason805 commented 5 years ago

I had included spring-cloud-bus:1.3.3-RELEASE in my project. But i found that the behavior of ObjectMapper was changed by comparing without using spring cloud bus.

I have a very simple case like below

public class TestDomain {
        private String name;
        private Date createTime;
}

@RestController
public class TestController {

    @RequestMapping("/test")
    public TestDomain test(){
        TestDomain domain = new TestDomain();
        domain.setName("Test");
        domain.setCreateTime(new Date());
        return domain;
    }
}

When accessing http://localhost:8080/test, what i expect it should be

{"name":"Test","createTime":1560956260744}

but i found after included spring cloud bus, the result looks like

{"name":"Test","createTime":"2019-06-19T15:00:35.124+0000"}

and i traced the code, found that BusJacksonAutoConfiguration has created a bean BusJacksonMessageConverter, which changed some behavior of the global injected ObjectMapper

    public void afterPropertiesSet() throws Exception {
        this.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        this.mapper.registerModule(new SubtypeModule(findSubTypes()));
    }

Actually, what i want is keep the ObjectMapper work as usual, how can i do that? I tried to create a higher precedence AutoConfiguration by extending BusJacksonAutoConfiguration and override busJsonConverter() method, to create BusJacksonMessageConverter by passing a null parameter, but failed since the BusJacksonMessageConverter is unvisiable, so what's the suggested way to do that?

BTW,what's the purpose to set SerializationFeature.WRITE_DATES_AS_TIMESTAMPS as false?

spencergibb commented 5 years ago

Please learn how to properly format code and logs.

See #147

leason805 commented 5 years ago

thanks

spencergibb commented 5 years ago

I marked this as a bug to fix on the 1.3.x branch, reopening.

spencergibb commented 4 years ago

Closing as 1.x is no longer maintained