com.google.gson.JsonSyntaxException when deserialize V1Secret json which returned by the api
See original GitHub issueV1Secret.data is the Map<String, byte[]>, but the CoreV1Api return the json like:
"data":{"test1":"ZEdWemRHUmhkR0V4","test2":"ZEdWemRHUmhkR0V5"}
It can not be handled by the com.google.gson.internal.bind.ArrayTypeAdapter, the stack trace is:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 284 path $.data.
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
at com.google.gson.Gson.fromJson(Gson.java:879)
at com.google.gson.Gson.fromJson(Gson.java:844)
at com.google.gson.Gson.fromJson(Gson.java:793)
at io.kubernetes.client.JSON.deserialize(JSON.java:106)
at io.kubernetes.client.ApiClient.deserialize(ApiClient.java:668)
at io.kubernetes.client.ApiClient.handleResponse(ApiClient.java:871)
at io.kubernetes.client.ApiClient.execute(ApiClient.java:798)
at io.kubernetes.client.apis.CoreV1Api.createNamespacedSecretWithHttpInfo(CoreV1Api.java:9095)
at io.kubernetes.client.apis.CoreV1Api.createNamespacedSecret(CoreV1Api.java:9079)
at com.ibm.bpm.mon.oi.bridge.k8s.KubeService.createSecret(KubeService.java:89)
at com.ibm.bpm.mon.oi.bridge.k8s.KubeServiceTest.testCreateSecret(KubeServiceTest.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 284 path $.data.
at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:70)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:187)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:145)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216)
... 36 more
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
com.google.gson.JsonSyntaxException: java.lang ...
RoutingTable contains class variable which is transient, It is used to indicate that a field should not be serialized.
Read more >JSON (client-java-api 3.0.0 API) - javadoc.io
Serialize the given Java object into JSON string. Parameters: obj - Object; Returns: String representation of the JSON. deserialize.
Read more >Google GSON for JSON Processing - Spring Framework Guru
In this post I show you how to GSON to work with JSON. ... to JSON, transmit the JSON data over a network,...
Read more >Leveraging the Gson Library | CodePath Android Cliffnotes
Google's Gson library provides a powerful framework for converting ... Based on the JSON response returned for this API call, let's first define...
Read more >Gson - How to convert Java object to / from JSON - Mkyong.com
App : have 5 REST API endpoints which need to be sent to the server (here I need to create the virtual server...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If the temporary workaround were put into the real source, it would look something like the diff below. Of course, the JSON code uses TypeAdapters instead of JsonSerializer and JsonDeserializer so it is probably not the correct change.
private ByteArrayBase64StringTypeAdapter base64TypeAdapter = new ByteArrayBase64StringTypeAdapter();
public JSON() { gson = new GsonBuilder() @@ -48,6 +47,7 @@ public class JSON { .registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter) .registerTypeAdapter(DateTime.class, dateTimeTypeAdapter) .registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
}
/**
public static class ByteArrayBase64StringTypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> {
}
Re-opening this, the correct fix is in #219