본문 바로가기

JSON

[Play Framework2] Json polymorphism Scala에서는 동적으로 Json 으로 변환하기가 힘들다. 그래서 찾은 방법이 trait을 만들어서 상속을 통한 방법이다. trait Person object Person { implicit val shapeWrites = Writes[Person] { person => person match { case student: Student => Json.writes[Student].writes(student) case teacher: Teacher => Json.writes[Teacher].writes(teacher) case parent: Parent => Json.writes[Parent].writes(parent)}} } @Entity@Table (name = "teacher")case class Te.. 더보기
[Play Framework2] JPA & Json model Java는 POJO 객체로 JPA와 Json이 아주 자유로웠지만 Scala에서는 정말 헤매는 부분이 많았다. 그리고 본인이 가장 간편하다고 생각하는 방법을 설명하겠다. 특별히 Play Framework2 이외에 다른 라이브러리를 사용하지 않고 내부적인 라이브러리를 통해 쉬운 방법을 찾았다. (one to many 와 many to many 는 아직 방법을 찾지 못함..) import play.db.jpa._import javax.persistence._import play.api.libs.json._import play.api.libs.functional.syntax._import scala.annotation.meta.field @Entity@Table (name = "class")case class .. 더보기
[Node.js] Json-RPC 라이브러리 Node.js에서 json-RPC 2.0 으로 연동할 때 찾아서 쓴 라이브러리이다. Java로만 구현해서 Java처럼 비슷하게 쓴것을 찾았다... Jayson 이라는 라이브러리이며 홈페이지는 여기~! - 사용법 -var jayson = require(__dirname + '/../..'); var client = jayson.client.http('http://localhost:3000');client.request('add', [1, 1], function(err, error, response) { if(err) throw err; console.log(response); // 2! }); 더보기
[Play Framework] Json RPC Client구현하기 Json-RPC로 사용할 라이브러리는 jsonrpc4j 이다. 자세한 사항은 여기로~! 이전 게시글과 연동하여 사용할 것이다. Spring Framework로 구현한 Json RPC Server를 참고!! 1. 라이브러리 추가하자 com.github.briandilley.jsonrpc4j jsonrpc4j 1.0 com.fasterxml.jackson.core jackson-core 2.0.2 com.fasterxml.jackson.core jackson-databind 2.0.2 com.fasterxml.jackson.core jackson-annotations 2.0.2 2. Serve에서 구현된 Model과 Service를 사용하므로 파일을 추가하자~! 3. RPC 테스트 클래스 생성 코드를 보면 .. 더보기
[Spring Framework] Json RPC Server 구현하기 Json-RPC로 사용할 라이브러리는 jsonrpc4j 이다. 자세한 사항은 여기로~! 이제 시작해보자~! 1. 우선은 라이브러리를 추가하자~! com.github.briandilley.jsonrpc4j jsonrpc4j 1.0 com.fasterxml.jackson.core jackson-core 2.0.2 com.fasterxml.jackson.core jackson-databind 2.0.2 com.fasterxml.jackson.core jackson-annotations 2.0.2 위에 보면 jackson을 쓴다. 이미 사용하기 떄문에 jsonrpc4j 라이브러리만 추가~! 2. Service 설정 자 기존에 구현된 Service에서 @JsonRpcService 애노테이션을 사용하자~! 그럼 설.. 더보기
[Protocol] Json RPC란... - Remote procedure call protocol을 Json으로 간단히 표현한 것이다. (XML-RPC와 유사하다.) Data type과 command로 구성되어 있고 알람(요청만하고 서버에 결과값을 받지 않는 것)과 다중 호출이 가능하다. (이전에 호출한 것에대해 상관없이?) JSON-RPC is a remote procedure call protocol encoded in JSON. It is a very simple protocol (and very similar to XML-RPC), defining only a handful of data types and commands. JSON-RPC allows for notifications (data sent to the server that.. 더보기
[Spring framework] Controller에서 Json값으로 Retrun 하기 라이브러리를 추가해준다. pom.xml org.codehaus.jackson jackson-core-asl 1.9.4 org.codehaus.jacksonjackson-mapper-asl1.9.2compile 그리고 Context.xml 파일에 를 넣어준다. 마지막으로 Controller에서 @RequestMapping (value = "/get/kidId/{kidId}", method = RequestMethod.GET)public @ResponseBody ContactListResult getKidIdList ( @PathVariable("kidId") final int kidId ) {return new ContactListResult(Result.SUCESS, this.contactService... 더보기