相关疑难解决方法(0)

何时使用@JsonProperty属性以及它用于什么?

这豆'州':

public class State {

    private boolean isSet;

    @JsonProperty("isSet")
    public boolean isSet() {
        return isSet;
    }

    @JsonProperty("isSet")
    public void setSet(boolean isSet) {
        this.isSet = isSet;
    }

}
Run Code Online (Sandbox Code Playgroud)

使用ajax'success'回调通过线路发送:

        success : function(response) {  
            if(response.State.isSet){   
                alert('success called successfully)
            }
Run Code Online (Sandbox Code Playgroud)

这里需要注释@JsonProperty吗?使用它有什么好处?我想我可以删除这个注释而不会产生任何副作用.

在https://github.com/FasterXML/jackson-annotations/wiki/Jackson-Annotations上阅读这个注释我不知道什么时候需要使用它?

java ajax jackson

156
推荐指数
8
解决办法
33万
查看次数

HttpMessageNotWritableException:没有带有 OpenApi Spring 生成器的 [...] 预设 Content-Type 'null'] 转换器

我正在(gradle)spring boot 项目中使用 openAPI 实现 petstore API。我使用 openapi 生成器插件生成一个服务器并实现一个简单的请求:

@Service
@RestController
public class PetApiController implements PetApi {

    @Override
    public ResponseEntity<Pet> getPetById(Long petId) {
        Pet p = new Pet();
        p.setId(0L);
        p.setName("fido");
        p.setPhotoUrls(new ArrayList<String>());
        p.setStatus(StatusEnum.AVAILABLE);
        p.setTags(new ArrayList<Tag>());
        Category c = new Category();
        c.setId(3L);
        c.setName("dummy category");
        p.setCategory(c);
        
        ResponseEntity<Pet> r = new ResponseEntity<Pet>(p, HttpStatus.OK);
        
        return r;
    }
}
Run Code Online (Sandbox Code Playgroud)

我生成的 swagger-ui 为请求提供了 xml 和 json 查询,但 xml 似乎不起作用:

$ curl -X GET "http://localhost:8080/pet/1" -H  "accept: application/xml"; echo ""

$ curl -X GET "http://localhost:8080/pet/1" -H  "accept: …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot openapi-generator

12
推荐指数
4
解决办法
5万
查看次数

标签 统计

ajax ×1

jackson ×1

java ×1

openapi-generator ×1

spring ×1

spring-boot ×1