0

I have a JAR that contains the following Scala class:

class JsonAvroConverter(val sch : org.apache.avro.Schema) extends scala.AnyRef {
  def toJson(avroData : org.json4s.JValue) : org.json4s.JValue = { /* compiled code */ }
}

Now I need to be able to call the methods in the class from inside a Java project. I added Json4s in my POM and I have Json4s accessbile but I am not sure of a way to use that library from a Java context. I also tried doing something like this:

String myString = "{\"name\":\"bob\"}"
JsonMethods json = new Jsonmethods();
json.parse(myString);

But I am not able to instantiate JsonMethods in the first place.

summerNight
  • 1,446
  • 3
  • 25
  • 52
  • What is the error message in the latter case? There appears to be a typo in the second line of the second section of code. Should this read: `JsonMethods json = new JsonMethods();` instead? – Mike Allen Jul 13 '17 at 03:04
  • JsonMethods is a trait so it can't be instantiated as is. See this question - https://stackoverflow.com/questions/7637752/using-scala-traits-with-implemented-methods-in-java for more info. – Rahul Jul 13 '17 at 10:35

0 Answers0