-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from roldanx/issue-1
Issue 1
- Loading branch information
Showing
5 changed files
with
292 additions
and
78 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
oskar-spark/src/main/java/org/opencb/oskar/spark/commons/PythonUtils.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,34 @@ | ||
package org.opencb.oskar.spark.commons; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.MapperFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
|
||
import java.io.IOException; | ||
|
||
public class PythonUtils { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public PythonUtils() { | ||
objectMapper = new ObjectMapper() | ||
.configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true) | ||
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false) | ||
.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT); | ||
} | ||
|
||
public String toJsonString(Object obj) throws IOException { | ||
return objectMapper.writeValueAsString(obj); | ||
} | ||
|
||
public Object toJavaObject(String str, String className) throws ClassNotFoundException, IOException { | ||
return objectMapper.readValue(str, Class.forName(className)); | ||
} | ||
|
||
public <T> T toJavaObject(String str, Class<T> clazz) throws IOException { | ||
return objectMapper.readValue(str, clazz); | ||
} | ||
|
||
} |
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.