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

Solve the issue of converting JSON int array to double array #85

Merged
merged 1 commit into from
Nov 18, 2019
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 @@ -429,7 +429,7 @@ private Event convertToSingleEventForDefaultMapping(Object eventObject) throws I
case START_OBJECT:
case START_ARRAY:
jsonObjectNode = objectMapper.readTree(eventObject.toString()).findValue(key);
data[position] = gson.fromJson(jsonObjectNode.toString(), Object.class);
data[position] = objectMapper.readValue(jsonObjectNode.toString(), Object.class);
handleJsonObject(jsonObjectNode, parser);
break;
case VALUE_STRING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.siddhi.extension.map.json.sourcemapper;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import io.siddhi.core.SiddhiAppRuntime;
import io.siddhi.core.SiddhiManager;
Expand All @@ -40,6 +41,7 @@ public class JsonSourceMapperTestCase {
private final int waitTime = 2000;
private final int timeout = 30000;
private AtomicInteger count = new AtomicInteger();
private ObjectMapper objectMapper = new ObjectMapper();

@BeforeMethod
public void init() {
Expand Down Expand Up @@ -1621,15 +1623,15 @@ public void jsonSourceMapperTest28() throws Exception {
SiddhiManager siddhiManager = new SiddhiManager();
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
Gson gson = new Gson();
Object jsonObject1 = gson.fromJson("[25,25]", Object.class);
Object jsonObject2 = gson.fromJson("{\"lkr\":55.678}", Object.class);
Object jsonObject3 = gson.fromJson("{\"prices\":25, \"priceArray\":[25,25]}", Object.class);
Object jsonObject4 = gson.fromJson("{\"price\":25, \"priceArray\":[25,25,25], " +
Object jsonObject1 = objectMapper.readValue("[25,25]", Object.class);
Object jsonObject2 = objectMapper.readValue("{\"lkr\":55.678}", Object.class);
Object jsonObject3 = objectMapper.readValue("{\"prices\":25, \"priceArray\":[25,25]}", Object.class);
Object jsonObject4 = objectMapper.readValue("{\"price\":25, \"priceArray\":[25,25,25], " +
"\"priceObject\":{\"price\":25,\"amount\":5,\"items\":[1,2,3]}}", Object.class);
Object jsonObject5 = new Gson().fromJson("{\"price\":25, \"priceArray\":[25,25,25], " +
Object jsonObject5 = objectMapper.readValue("{\"price\":25, \"priceArray\":[25,25,25], " +
"\"priceObject\":{\"price\":25,\"amount\":5,\"items\":[{\"id\":1},{\"id\":2},{\"id\":3}]}}", Object
.class);
Object jsonObject6 = new Gson().fromJson("{\"price\":25, \"priceArray\":[{\"lkr\":25},{\"lkr\":25}," +
Object jsonObject6 = objectMapper.readValue("{\"price\":25, \"priceArray\":[{\"lkr\":25},{\"lkr\":25}," +
"{\"lkr\":25}], " +
"\"priceObject\":{\"price\":25,\"amount\":5,\"items\":[{\"id\":1},{\"id\":2},{\"id\":3}]}}", Object
.class);
Expand Down Expand Up @@ -1760,9 +1762,6 @@ public void receive(Event[] events) {
"{\"lkr\":25}],\"priceObject\":{\"price\":25,\"amount\":5,\"items\":[{\"id\":1}," +
"{\"id\":2},{\"id\":3}]}}", event.getData(1));
break;
// case 1:
// AssertJUnit.assertEquals("true", event.getData(0));
// break;
default:
AssertJUnit.fail();
}
Expand Down