2023-04-16
This commit is contained in:
16
gson/build.gradle.kts
Normal file
16
gson/build.gradle.kts
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("elex-java")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
|
||||
}
|
||||
20
gson/logback.xml
Normal file
20
gson/logback.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Examples for Java
|
||||
~
|
||||
~ Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
~ https://www.elex-project.com/
|
||||
-->
|
||||
|
||||
<configuration>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="TRACE">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
</configuration>
|
||||
32
gson/src/main/java/kr/pe/elex/examples/GsonSample.java
Normal file
32
gson/src/main/java/kr/pe/elex/examples/GsonSample.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import com.elex_project.abraxas.Console;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class GsonSample {
|
||||
|
||||
public static void main(String... args){
|
||||
Gson gson = new GsonBuilder().create();
|
||||
|
||||
// to json
|
||||
Person charlie = new Person("Charlie", 13);
|
||||
String json = gson.toJson(charlie);
|
||||
Console.writeLine(json);
|
||||
|
||||
// from json
|
||||
Person steve = gson.fromJson("{'name':'Steve', 'age':43}", Person.class);
|
||||
Console.writeLine(steve);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
22
gson/src/main/java/kr/pe/elex/examples/Person.java
Normal file
22
gson/src/main/java/kr/pe/elex/examples/Person.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Examples for Java
|
||||
*
|
||||
* Copyright (c) 2023. Elex. All Rights Reserved.
|
||||
* https://www.elex-project.com/
|
||||
*/
|
||||
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class Person {
|
||||
private String name;
|
||||
private int age;
|
||||
}
|
||||
Reference in New Issue
Block a user