我有以下指令.
directivesModule.directive('wikis', function() {
var urlRegex = new RegExp('^(https?)://.+$');
return {
restrict: 'E',
templateUrl: 'templates/wiki-list.html',
scope: {
wikis: '='
},
link: function(scope, element, attrs) {
scope.newWikiURL = '';
scope.$watch('wikis', function() {
if (scope.wikis == undefined || scope.wikis.length === 0) {
scope.class = 'hide';
} else {
scope.class = 'show';
}
}, false);
scope.addWiki = function() {
if (scope.wikis == undefined) {
scope.wikis = [];
}
var nw = scope.newWikiURL;
if (nw != undefined && nw.trim() != '' && urlRegex.exec(nw)) { …Run Code Online (Sandbox Code Playgroud) 我发现自己处于一种需要将JSON序列化为非案例类的情况.
有一个班级:
class MyClass(val name: String) {
def SaySomething() : String = {
return "Saying something... "
}
}
Run Code Online (Sandbox Code Playgroud)
我为这个类创建了一个JsonProtocol:
object MyClassJsonProtocol extends DefaultJsonProtocol {
implicit object MyClassJsonFormat extends JsonWriter[MyClass] {
override def write(obj: MyClass): JsValue =
JsObject(
"name" -> JsString(obj.name)
)
}
}
Run Code Online (Sandbox Code Playgroud)
稍后在代码中导入协议..
val aListOfMyClasses = List[MyClass]() ... // lets assume that has items and not an empty list
import spray.json._
import MyClassJsonProtocol._
val json = aListOfMyClasses.toJson
Run Code Online (Sandbox Code Playgroud)
在尝试构建项目时,我收到以下错误:
找不到类型为List [MyClass]的JsonWriter或JsonFormat
spray-json已经有了通用列表的格式,我正在为我的班级提供一种格式,会出现什么问题?
提前致谢...!!!