forked from apache/incubator-kie-drools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DROOLS-4698] Managing user defined expressions for Collections (apac…
…he#2691) * DROOLS-4698: Managing expressions for Collections * DROOLS-4698: Managing expressions for Collections * DROOLS-4698: Managing expressions for Collections + Tests * DROOLS-4698: Managing expressions for Collections + Tests * DROOLS-4698: Managing expressions for Collections + Tests * DROOLS-4698: Managing expressions for Collections + Tests * DROOLS-4698: Managing expressions for Collections + Tests * DROOLS-4698: Managing expressions for Collections + Tests * DROOLS-4698: Managing expressions for Collections + Tests * Merging from origin/master * DROOLS-4698: Changes required during CR * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Changes required during Code Review * DROOLS-4698: Additional tests. * DROOLS-4698: Increase coverage (#2) Co-authored-by: Jozef Marko <jomarko@redhat.com>
- Loading branch information
1 parent
ff514ea
commit 0c0202b
Showing
11 changed files
with
413 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...imulation-backend/src/main/java/org/drools/scenariosimulation/backend/util/JsonUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2019 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.drools.scenariosimulation.backend.util; | ||
|
||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.core.JsonParseException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** | ||
* Class used to provide JSON common utils | ||
*/ | ||
public class JsonUtils { | ||
|
||
private JsonUtils() { | ||
// Not instantiable | ||
} | ||
|
||
/** | ||
* This method aim is to to evaluate if any possible String is a valid json or not. | ||
* Given a json in String format, it try to convert it in a <code>JsonNode</code>. In case of success, i.e. | ||
* the given string is a valid json, it put the <code>JsonNode</code> in a <code>Optional</code>. An empty | ||
* <code>Optional</code> is passed otherwise. | ||
* @param json | ||
* @return | ||
*/ | ||
public static Optional<JsonNode> convertFromStringToJSONNode(String json) { | ||
if (json == null || json.isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
try { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JsonNode jsonNode = objectMapper.readTree(json); | ||
return Optional.of(jsonNode); | ||
} catch (JsonParseException e) { | ||
return Optional.empty(); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException("Generic error during json parsing: " + json, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.