Skip to content

chore: minor improvements #93

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

Open
wants to merge 2 commits into
base: develop
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ public JsonFlattenerFactory(Consumer<JsonFlattener> configurer, JsonCore<?> json
* @return a {@link JsonFlattener}
*/
public JsonFlattener build(String json) {
JsonFlattener jf;
if (jsonCore.isPresent()) {
jf = new JsonFlattener(jsonCore.get(), json);
} else {
jf = new JsonFlattener(json);
}
JsonFlattener jf = jsonCore
.map(core -> new JsonFlattener(core, json))
.orElseGet(() -> new JsonFlattener(json));
configurer.accept(jf);
return jf;
}
Expand All @@ -87,12 +84,9 @@ public JsonFlattener build(String json) {
* @return a {@link JsonFlattener}
*/
public JsonFlattener build(JsonValueBase<?> json) {
JsonFlattener jf;
if (jsonCore.isPresent()) {
jf = new JsonFlattener(jsonCore.get(), json);
} else {
jf = new JsonFlattener(json);
}
JsonFlattener jf = jsonCore
.map(core -> new JsonFlattener(core, json))
.orElseGet(() -> new JsonFlattener(json));
configurer.accept(jf);
return jf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ private JsonValueCore<?> parseJson(String json) {
* @param json a JSON string
*/
public JsonUnflattener(String json) {
jsonCore = new JacksonJsonCore();
root = parseJson(json);
this(new JacksonJsonCore(), json);
}

/**
Expand All @@ -158,8 +157,7 @@ public JsonUnflattener(JsonCore<?> jsonCore, String json) {
* @throws IOException if the jsonReader cannot be read
*/
public JsonUnflattener(Reader jsonReader) throws IOException {
jsonCore = new JacksonJsonCore();
root = jsonCore.parse(jsonReader);
this(new JacksonJsonCore(), jsonReader);
}

/**
Expand All @@ -181,8 +179,7 @@ public JsonUnflattener(JsonCore<?> jsonCore, Reader jsonReader) throws IOExcepti
* @param flattenedMap a flattened {@link Map}
*/
public JsonUnflattener(Map<String, ?> flattenedMap) {
jsonCore = new JacksonJsonCore();
root = jsonCore.parse(new JsonifyLinkedHashMap<>(flattenedMap).toString());
this(new JacksonJsonCore(), flattenedMap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ public JsonUnflattenerFactory(Consumer<JsonUnflattener> configurer, JsonCore<?>
* @return a {@link JsonUnflattener}
*/
public JsonUnflattener build(String json) {
JsonUnflattener jf;
if (jsonCore.isPresent()) {
jf = new JsonUnflattener(jsonCore.get(), json);
} else {
jf = new JsonUnflattener(json);
}

JsonUnflattener jf = jsonCore
.map(core -> new JsonUnflattener(core, json))
.orElseGet(() -> new JsonUnflattener(json));
configurer.accept(jf);
return jf;
}
Expand All @@ -88,12 +84,9 @@ public JsonUnflattener build(String json) {
* @return a {@link JsonUnflattener}
*/
public JsonUnflattener build(Map<String, ?> flattenedMap) {
JsonUnflattener jf;
if (jsonCore.isPresent()) {
jf = new JsonUnflattener(jsonCore.get(), flattenedMap);
} else {
jf = new JsonUnflattener(flattenedMap);
}
JsonUnflattener jf = jsonCore
.map(core -> new JsonUnflattener(core, flattenedMap))
.orElseGet(() -> new JsonUnflattener(flattenedMap));
configurer.accept(jf);
return jf;
}
Expand Down