Skip to content

Fix bug: JSON initialization block should be static #3371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static Class getClassByDiscriminator(Map classByDiscriminatorValue, Stri
return clazz;
}

{
static {
GsonBuilder gsonBuilder = createGson();
gsonBuilder.registerTypeAdapter(Date.class, dateTypeAdapter);
gsonBuilder.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import io.kubernetes.client.openapi.models.V1ListMeta;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.openapi.models.V1Status;
import okio.ByteString;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;

@TestMethodOrder(OrderAnnotation.class)
class JSONTest {

private final JSON json = new JSON();
@Order(0)
@Test
void serializeWithStaticMethod() {
JSON.serialize(new V1ObjectMeta());
}

@Test
void serializeByteArray() {
JSON json = new JSON();
final String plainText = "string that contains '=' when encoded";
final String base64String = json.serialize(plainText.getBytes());
// serialize returns string surrounded by quotes: "\"[base64]\""
Expand All @@ -48,6 +58,7 @@ void serializeByteArray() {

@Test
void offsetDateTime1e6Parse() {
JSON json = new JSON();
String timeStr = "\"2018-04-03T11:32:26.123456Z\"";
OffsetDateTime dateTime = json.deserialize(timeStr, OffsetDateTime.class);
String serializedTsStr = json.serialize(dateTime);
Expand All @@ -56,6 +67,7 @@ void offsetDateTime1e6Parse() {

@Test
void offsetDateTime1e4Parse() {
JSON json = new JSON();
String timeStr = "\"2018-04-03T11:32:26.1234Z\"";
OffsetDateTime dateTime = json.deserialize(timeStr, OffsetDateTime.class);
String serializedTsStr = json.serialize(dateTime);
Expand All @@ -65,6 +77,7 @@ void offsetDateTime1e4Parse() {

@Test
void offsetDateTime1e3Parse() {
JSON json = new JSON();
String timeStr = "\"2018-04-03T11:32:26.123Z\"";
OffsetDateTime dateTime = json.deserialize(timeStr, OffsetDateTime.class);
String serializedTsStr = json.serialize(dateTime);
Expand All @@ -74,6 +87,7 @@ void offsetDateTime1e3Parse() {

@Test
void offsetDateTimeNoFractionParse() {
JSON json = new JSON();
String timeStr = "\"2018-04-03T11:32:26Z\"";
OffsetDateTime dateTime = json.deserialize(timeStr, OffsetDateTime.class);
String serializedTsStr = json.serialize(dateTime);
Expand Down
Loading