-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added possibility to create ObjectMapper with custom Yaml/Json Factor…
…y class (#4397) * Added possibility to create ObjectMapper using ObjectMapperFactory with custom Yaml/Json Factory class. * Changed access modifiers to public in all methods of ObjectMapperFactory
- Loading branch information
1 parent
562e65d
commit 0e54312
Showing
5 changed files
with
811 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
modules/swagger-core/src/test/java/io/swagger/util/YamlSerializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.swagger.util; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import io.swagger.matchers.SerializationMatchers; | ||
import io.swagger.models.Swagger; | ||
import org.testng.annotations.Test; | ||
import org.yaml.snakeyaml.LoaderOptions; | ||
|
||
public class YamlSerializationTest { | ||
|
||
@Test | ||
public void testSerializeYAMLWithCustomFactory() throws Exception { | ||
// given | ||
LoaderOptions loaderOptions = new LoaderOptions(); | ||
loaderOptions.setCodePointLimit(5 * 1024 * 1024); | ||
YAMLFactory yamlFactory = YAMLFactory.builder() | ||
.loaderOptions(loaderOptions) | ||
.build(); | ||
final String yaml = ResourceUtils.loadClassResource(getClass(), "specFiles/petstore.yaml"); | ||
|
||
// when | ||
Swagger swagger = ObjectMapperFactory.createYaml(yamlFactory).readValue(yaml, Swagger.class); | ||
|
||
// then | ||
SerializationMatchers.assertEqualsToYaml(swagger, yaml); | ||
} | ||
|
||
@Test(expectedExceptions = JacksonYAMLParseException.class) | ||
public void testSerializeYAMLWithCustomFactoryAndCodePointLimitReached() throws Exception { | ||
// given | ||
LoaderOptions loaderOptions = new LoaderOptions(); | ||
loaderOptions.setCodePointLimit(1); | ||
YAMLFactory yamlFactory = YAMLFactory.builder() | ||
.loaderOptions(loaderOptions) | ||
.build(); | ||
final String yaml = ResourceUtils.loadClassResource(getClass(), "specFiles/petstore.yaml"); | ||
|
||
// when | ||
Swagger swagger = ObjectMapperFactory.createYaml(yamlFactory).readValue(yaml, Swagger.class); | ||
|
||
// then - Throw JacksonYAMLParseException | ||
} | ||
} |
Oops, something went wrong.