|
1 | 1 | package org.nlogo.extensions.py
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.core.json.JsonReadFeature |
| 4 | +import com.fasterxml.jackson.databind.json.JsonMapper |
| 5 | +import com.fasterxml.jackson.databind.ObjectMapper |
| 6 | + |
3 | 7 | import java.io.{ BufferedReader, Closeable, File, IOException, InputStreamReader }
|
4 | 8 | import java.lang.ProcessBuilder.Redirect
|
5 | 9 | import java.nio.file.Paths
|
6 | 10 |
|
7 |
| -import com.fasterxml.jackson.core.json.JsonReadFeature |
8 |
| -import com.fasterxml.jackson.databind.json.JsonMapper |
| 11 | +import org.json4s.jackson.{ JsonMethods, Json4sScalaModule } |
9 | 12 |
|
10 | 13 | import org.nlogo.languagelibrary.Subprocess.path
|
11 | 14 | import org.nlogo.languagelibrary.Subprocess
|
@@ -65,7 +68,6 @@ class PythonExtension extends api.DefaultClassManager {
|
65 | 68 |
|
66 | 69 | override def runOnce(em: ExtensionManager): Unit = {
|
67 | 70 | super.runOnce(em)
|
68 |
| - JsonMapper.builder().configure(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS, true) |
69 | 71 |
|
70 | 72 | val py2Message = s"It is recommended to use Python 3 if possible and enter its path above. If you must use Python 2, enter the path to its executable folder below."
|
71 | 73 | val py2Property = new FileProperty("python2", "python2", PythonExtension.config.get("python2").getOrElse(""), py2Message)
|
@@ -127,7 +129,13 @@ object SetupPython extends api.Command {
|
127 | 129 | val pyFile = if (maybePyFile.exists) { maybePyFile } else { (new File("pyext.py")).getCanonicalFile }
|
128 | 130 | val pyScript: String = pyFile.toString
|
129 | 131 | try {
|
130 |
| - PythonExtension.pythonProcess = Subprocess.start(context.workspace, pythonCmd, Seq(pyScript), PythonExtension.codeName, PythonExtension.longName) |
| 132 | + val mapper = new JsonMethods { |
| 133 | + override def mapper: ObjectMapper = |
| 134 | + JsonMapper.builder.addModule(new Json4sScalaModule).enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS).build() |
| 135 | + } |
| 136 | + PythonExtension.pythonProcess = Subprocess.start(context.workspace, pythonCmd, Seq(pyScript), |
| 137 | + PythonExtension.codeName, PythonExtension.longName, |
| 138 | + customMapper = Option(mapper)) |
131 | 139 | PythonExtension.menu.foreach(_.setup(PythonExtension.pythonProcess.evalStringified))
|
132 | 140 | } catch {
|
133 | 141 | case e: Exception =>
|
|
0 commit comments