Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果我在application.properties中使用json-to-gson映射器属性,为什么swagger不起作用_Java_Rest_Spring Boot_Swagger Ui_Swagger 2.0 - Fatal编程技术网

Java 如果我在application.properties中使用json-to-gson映射器属性,为什么swagger不起作用

Java 如果我在application.properties中使用json-to-gson映射器属性,为什么swagger不起作用,java,rest,spring-boot,swagger-ui,swagger-2.0,Java,Rest,Spring Boot,Swagger Ui,Swagger 2.0,我们在spring boot application.properties中使用spring.http.converters.preferredJSON mapper=gson属性将Junit测试用例的json转换为gson。不确定是什么原因导致此属性虚张声势 与swagger集成时出现抓取错误。我知道这是一篇“旧”帖子,您可能仍然有答案。春天的靴子有什么神奇的作用。根据您的应用程序配置(依赖项、类、文件等),它将尝试自动配置您的应用程序 因此,默认情况下,您有此spring配置 # HTTP

我们在spring boot application.properties中使用spring.http.converters.preferredJSON mapper=gson属性将Junit测试用例的json转换为gson。不确定是什么原因导致此属性虚张声势

与swagger集成时出现抓取错误。

我知道这是一篇“旧”帖子,您可能仍然有答案。春天的靴子有什么神奇的作用。根据您的应用程序配置(依赖项、类、文件等),它将尝试自动配置您的应用程序

因此,默认情况下,您有此spring配置

# HTTP (HttpProperties)
spring.http.converters.preferred-json-mapper= # Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment.
要启用gson,必须包含gson依赖项:

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.4</version>
</dependency>
# Preferred JSON mapper to use for HTTP message conversion.
spring.http.converters.preferred-json-mapper=gson
在spring引导中配置Gson

# GSON ([GsonProperties][1])
spring.gson.date-format= # Format to use when serializing Date objects.
spring.gson.disable-html-escaping= # Whether to disable the escaping of HTML characters such as '<', '>', etc.
spring.gson.disable-inner-class-serialization= # Whether to exclude inner classes during serialization.
spring.gson.enable-complex-map-key-serialization= # Whether to enable serialization of complex map keys (i.e. non-primitives).
spring.gson.exclude-fields-without-expose-annotation= # Whether to exclude all fields from consideration for serialization or deserialization that do not have the "Expose" annotation.
spring.gson.field-naming-policy= # Naming policy that should be applied to an object's field during serialization and deserialization.
spring.gson.generate-non-executable-json= # Whether to generate non executable JSON by prefixing the output with some special text.
spring.gson.lenient= # Whether to be lenient about parsing JSON that doesn't conform to RFC 4627.
spring.gson.long-serialization-policy= # Serialization policy for Long and long types.
spring.gson.pretty-printing= # Whether to output serialized JSON that fits in a page for pretty printing.
spring.gson.serialize-nulls= # Whether to serialize null fields.
#GSON([GsonProperties][1])
spring.gson.date format=#序列化日期对象时使用的格式。
disable html转义=#是否禁用转义html字符,如“”,等等。
禁用内部类序列化=#是否在序列化过程中排除内部类。
enable complex map key serialization=#是否启用复杂映射键(即非原语)的序列化。
spring.gson.exclude fields without expose annotation=#是否将没有“expose”注释的所有字段排除在序列化或反序列化考虑之外。
field naming policy=#在序列化和反序列化期间应应用于对象字段的命名策略。
generate non-executable json=#是否通过在输出前添加一些特殊文本来生成不可执行的json。
green=#是否要对不符合RFC4627的JSON进行宽松解析。
long序列化策略=#long和long类型的序列化策略。
spring.gson.pretty printing=#是否输出适合页面进行pretty printing的序列化JSON。
spring.gson.serialize nulls=#是否序列化空字段。
您还可以在项目中完全排除jackson,执行以下操作:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <!-- Exclude the default Jackson dependency -->
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-json</artifactId>
        </exclusion>
    </exclusions>
</dependency>

org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
spring启动程序json