I want to print the contents of a collection and I've tried with the mkString method, but it gives me still not the right content of the object.
My code: package org.template
import org.apache.predictionio.controller.LServing
class Serving
extends LServing[Query, PredictedResult] {
override
def serve(query: Query,
predictedResults: Seq[PredictedResult]): PredictedResult = {
println(predictedResults.mkString("\n"))
predictedResults.head
}
}
The response:
predictedResult([Lorg.template.ItemScore;@2fb3a837,[Lorg.template.Rule;@5cfc70a8)
Definition of the PredictedResult class:
package org.template
import org.apache.predictionio.controller.EngineFactory
import org.apache.predictionio.controller.Engine
// Query most similar (top num) items to the given
case class Query(items: Set[String], num: Int) extends Serializable
case class PredictedResult(itemScores: Array[ItemScore], rules: Array[Rule]) extends Serializable
If
PredictedResultis a case class like sothen we get nice output
However if it is a regular class like so
then we get
To get the nice output for regular class we need to override its
toStringmethod like sowhich now outputs
Addressing the comment we have
which outputs
If we change from
ArraytoListlike sothen we get nice output out-of-the-box without the need to override
toString