Skip to content
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

fix 'JsonException: JSONArray initial value should be a string or col… #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The most simple way to use this SDK is to pull from the Predix Snapshot artifact
<dependency>
<groupId>com.ge.predix.eventhub</groupId>
<artifactId>predix-event-hub-sdk</artifactId>
<version>2.2.4</version>
<version>2.2.5</version>
</dependency>
...
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.ge.predix.eventhub</groupId>
<artifactId>predix-event-hub-sdk</artifactId>
<version>2.2.4</version> <!--- NOTE: also change version in readme and log statement in Client class -->
<version>2.2.5</version> <!--- NOTE: also change version in readme and log statement in Client class -->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ge/predix/eventhub/EventHubUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static void putIntoJson(JSONObject jsonObj, String key, Object value){
for(Object o : (List) value){
array.put(o);
}
jsonObj.put(key, new JSONArray(value));
jsonObj.put(key, new JSONArray(((List) value)));
return;
}
jsonObj.put(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ge/predix/eventhub/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class Client implements AutoCloseable {
private static final String healthCheckUrl = "predix-event-hub.grpc.health";
private static final Long ttlHealth = 30000L;
private static final String sdkVersionString = "2.2.4";
private static final String sdkVersionString = "2.2.5";


private Channel channel;
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/com/ge/predix/eventhub/client/EventHubUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.ge.predix.eventhub.*;
import com.ge.predix.eventhub.configuration.LoggerConfiguration;
import com.ge.predix.eventhub.test.categories.DefectTest;
import com.ge.predix.eventhub.test.categories.SanityTest;
import com.ge.predix.eventhub.test.categories.SmokeTest;
import com.google.protobuf.ByteString;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -313,4 +317,35 @@ public void testLogLevels(){
}
}

/**
* test serializing messages for logging with nested object, e.g.
* {
* "publisher_msg":{
* "msg":"ignoring values from config, don't apply to this publisher type",
* "ignores":[
* "timeout",
* 10000
* ]
* }
* }
*/
@Test
@Category(DefectTest.class)
public void test() {
final List<Object> ignores = new ArrayList<>();
final String timeoutKey = "timeout";
final long timeoutValue = 10000L;
ignores.add(timeoutKey);
ignores.add(timeoutValue);
JSONObject jsonObject = EventHubUtils.formatJson(
"publisher_msg",
"msg",
"ignoring values from config, don't apply to this publisher type",
"ignores",
ignores
);
final JSONArray ignoresJsonValue = jsonObject.getJSONObject("publisher_msg").getJSONArray("ignores");
Assert.assertEquals(ignores, ignoresJsonValue.toList());
}

}