首页 > 其他 > 详细

一些小坑

时间:2017-10-22 18:07:03      阅读:227      评论:0      收藏:0      [点我收藏+]

一、使用jackson反序列化时存在多余字段:

Unrecognized field "xxx" (……), not marked as ignorable (5 known properties: "xxxxxxxxx",

反序列化字段未匹配上,忽略掉这些字段:


public class JsonUtil {

public static final ObjectMapper objectMapper;

static {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

}

二、swagger配置开发环境:

@Profile("dev")  //指定只可以在dev环境看到接口doc
@Configuration
@EnableSwagger2
@Profile("dev")
@ComponentScan("com.xxx.xxx.controller")
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfoBuilder().title("Service APIs")
                .description("Service APIs")
                .license("xxx")
                .licenseUrl("http://www.xxx.com")
                .version("1.0")
                .build();

        return apiInfo;
    }
}

 三、modelmapper的严格匹配:

    private ModelMapper mapper;

    /**
     * init mapper
     */
    public DemoController() {
        this.mapper = new ModelMapper();
        this.mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
    }

 

一些小坑

原文:http://www.cnblogs.com/mr-yang-localhost/p/7709759.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!