-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
buildscript { | ||
ext { | ||
springBootVersion = '2.1.3.RELEASE' | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") | ||
} | ||
plugins { | ||
id 'org.springframework.boot' version '2.1.3.RELEASE' | ||
id 'org.jetbrains.kotlin.jvm' version '1.2.71' | ||
id 'org.jetbrains.kotlin.plugin.spring' version '1.2.71' | ||
} | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'eclipse' | ||
apply plugin: 'org.springframework.boot' | ||
apply plugin: 'io.spring.dependency-management' | ||
|
||
group = 'com.example' | ||
version = '0.0.1-SNAPSHOT' | ||
sourceCompatibility = 1.8 | ||
sourceCompatibility = '1.8' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile('org.springframework.boot:spring-boot-starter-web') | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin' | ||
implementation 'org.jetbrains.kotlin:kotlin-reflect' | ||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
testCompile('org.springframework.boot:spring-boot-starter-test') | ||
compileKotlin { | ||
kotlinOptions { | ||
freeCompilerArgs = ['-Xjsr305=strict'] | ||
jvmTarget = '1.8' | ||
} | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions { | ||
freeCompilerArgs = ['-Xjsr305=strict'] | ||
jvmTarget = '1.8' | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
SpringBootCustomJackson/src/main/java/com/example/component/EncodedJsonComponent.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...e/SpringBootCustomJacksonApplication.java → ...a/SpringBootCustomJacksonApplication.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.example; | ||
package com.example.java; | ||
|
||
import java.util.Arrays; | ||
|
||
|
62 changes: 62 additions & 0 deletions
62
SpringBootCustomJackson/src/main/java/com/example/java/component/EncodedJsonComponent.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,62 @@ | ||
package com.example.java.component; | ||
|
||
import com.example.java.domain.Model; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.ObjectCodec; | ||
import com.fasterxml.jackson.databind.*; | ||
import org.springframework.boot.jackson.JsonComponent; | ||
import org.springframework.util.Base64Utils; | ||
|
||
import java.io.IOException; | ||
import java.util.Iterator; | ||
|
||
@JsonComponent | ||
public class EncodedJsonComponent { | ||
|
||
public static class DecyptDataDeserializer extends JsonDeserializer<Model> { | ||
|
||
@Override | ||
public Class<?> handledType() { | ||
return Model.class; | ||
} | ||
|
||
@Override | ||
public Model deserialize(JsonParser p, DeserializationContext ctxt) | ||
throws IOException { | ||
ObjectCodec codec = p.getCodec(); | ||
JsonNode node = codec.readTree(p); | ||
|
||
Iterator<String> it = node.fieldNames(); | ||
while (it.hasNext()) { | ||
String field = it.next(); | ||
System.out.println(field + ":" + node.get(field)); | ||
} | ||
|
||
String name = new String(Base64Utils.decodeFromString(node.get("name").asText())); | ||
int type = node.get("type").asInt(); | ||
System.out.println("---------------------------------------------------"); | ||
return new Model(name, type); | ||
} | ||
} | ||
|
||
public static class EncyptDataSerializer extends JsonSerializer<Model> { | ||
|
||
@Override | ||
public Class<Model> handledType() { | ||
return Model.class; | ||
} | ||
|
||
@Override | ||
public void serialize(Model value, JsonGenerator json, | ||
SerializerProvider provider) throws IOException { | ||
json.writeStartObject(); | ||
json.writeFieldName("name"); | ||
json.writeString(Base64Utils.encodeToString(value.getName().getBytes())); | ||
json.writeFieldName("type"); | ||
json.writeNumber(value.getType()); | ||
json.writeEndObject(); | ||
} | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...c/main/java/com/example/domain/Model.java → ...n/java/com/example/java/domain/Model.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.example.domain; | ||
package com.example.java.domain; | ||
|
||
public class Model { | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...java/com/example/web/BasicController.java → ...com/example/java/web/BasicController.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