Json 使用对象映射器时,groovy中的输出格式不同。为什么?

Json 使用对象映射器时,groovy中的输出格式不同。为什么?,json,groovy,restful-architecture,object-object-mapping,Json,Groovy,Restful Architecture,Object Object Mapping,为什么我到处都能得到\呢 我使用的方法: @RequestMapping(value = '/showFromMongo', method = RequestMethod.GET) def showFromMongoDB() { //println 'testit' def obj = repository.findByLastName("Vinodh"); ObjectMapper myObjectMapper = new Object

为什么我到处都能得到\呢

我使用的方法:

@RequestMapping(value = '/showFromMongo', method = RequestMethod.GET)
    def showFromMongoDB() {
        //println 'testit'
        def obj = repository.findByLastName("Vinodh");

        ObjectMapper myObjectMapper = new ObjectMapper();
        myObjectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
        def temp = []
        obj.collect{
            temp <<  myObjectMapper.writeValueAsString(it)
            }
        temp
    }

如何消除\.

好问题,我在使用Newtonsoft json时也遇到了同样的问题@维克兰特,如果这是一个好问题,请向上投票。你是如何看待输出的?作为旁白,这是一个类似rest的架构;不是RESTful。返回一个字符串数组。此处的\将被引用。当使用collect时,不需要临时变量。
[  
   "{\"id\":\"54fe7bbfd416859826ae53ea\",\"firstName\":\"Priya\",\"lastName\":\"Vinodh\"}",
   "{\"id\":\"54fe7be8d416f74f961678fa\",\"firstName\":\"Mrithula\",\"lastName\":\"Vinodh\"}"
]