[英]Using java classes in Play framework with Scala to be returned as Json Object
I have some java classes which were generated using axis wsdl2java. 我有一些使用轴wsdl2java生成的Java类。 I want to use those classes to be returned in Json format, but i keep getting various error, such as
cannot convert Incident Object to HttpResponse try to make it writable
. 我想使用那些类以Json格式返回,但是我不断遇到各种错误,例如
cannot convert Incident Object to HttpResponse try to make it writable
。
When tried using Writable
it asks me to check if it have apply
method. 当尝试使用
Writable
它要求我检查它是否具有apply
方法。
Is there any swift way i can use java classes as is, without going through hassle of making it case classes. 有没有任何快速的方法可以按原样使用Java类,而无需经历使其成为case类的麻烦。
You try to render a class directly with Ok(MyClass())
and this is not possible. 您尝试直接使用
Ok(MyClass())
渲染类,而这是不可能的。 You have to render it as Json
or String
or any Writable. 您必须将其呈现为
Json
或String
或任何可写形式。 Json
is probably the best choice. Json
可能是最好的选择。 You should use a library like play-json, circe or one of the several others and render you response with Ok(Json.toJson(Myclass()))
(for play-json) or equivalent. 您应该使用诸如play-json,circe之类的库或其他几个库中的一个,并使用
Ok(Json.toJson(Myclass()))
(对于play-json)或等效方法来呈现响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.