-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scaffold): support integration with gson
- Loading branch information
Showing
5 changed files
with
95 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const _ = require('lodash'); | ||
|
||
module.exports = { | ||
key: 'gson', | ||
fn: { | ||
configureProviderPomDependencies (optionalDependencies, props) { | ||
optionalDependencies.push({ | ||
dependency: [ | ||
{ groupId: 'com.google.code.gson' }, | ||
{ artifactId: 'gson' } | ||
] | ||
}) | ||
}, | ||
configureApplicationYaml (yaml, env, props) { | ||
switch (env) { | ||
case 'default': { | ||
_.merge(yaml, { | ||
spring: { | ||
http: { | ||
converters: { | ||
'preferred-json-mapper': 'gson' | ||
} | ||
} | ||
} | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
...rtifactId}-provider/src/main/java/${basePath}/config/web/if_gson.GsonConfigurer.tmpl.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,27 @@ | ||
package ${basePackage}.config.web; | ||
|
||
import com.google.gson.*; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import springfox.documentation.spring.web.json.Json; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
@Configuration | ||
public class GsonConfigurer implements WebMvcConfigurer { | ||
@Bean | ||
public GsonBuilder gsonBuilder() { | ||
GsonBuilder builder = new GsonBuilder(); | ||
// for spring fox swagger json serialization | ||
builder.registerTypeAdapter(Json.class, new JsonSerializer<Json>() { | ||
private JsonParser parser = new JsonParser(); | ||
|
||
@Override | ||
public JsonElement serialize(Json json, Type type, JsonSerializationContext jsonSerializationContext) { | ||
return parser.parse(json.value()); | ||
} | ||
}); | ||
return builder; | ||
} | ||
} |
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