2017-07-01 45 views
0

任何人都可以建议Clojure libarry,能够正确地反序列化具有复杂字段类型的对象,如UUID等。根据Clojure提供的JSON反序列化

我会分析是这样的:

JSON

{ 
    "_id": 42, 
    "property1": "uuid-value" 
} 

根据这样的事情:

模式

{ 
    "type" : "object", 
    "properties" : { 
     "_id" : {"type" : "integer"}, 
     "property1" : {"type" : "UUID"} 
    } 
} 

进入索姆ething这样的:

的Clojure表示

{:_id 42 :property1 UUID("uuid-value")} 
+1

你见过https://github.com/dakrone/cheshire? – Josh

+0

是的,它在编码部分完美的工作,但我问的是以柴郡条款解码。 – lllShamanlll

+0

看看[Transit格式](https://github.com/cognitect/transit-format)。它不使用JSON Schema,但它的设计明确,使得UUID和日期等在解码时转换为编程语言原生格式。 – ez121sl

回答

0

您可以尝试

(cheshire.core/parse-string "{\"_id\":\"someId\",\"property1\":\"uuid-value\"}" true) 
+0

因此,它只是将uuid-value解码为字符串。 – lllShamanlll

0

有关使用json-schema库是什么?它似乎只是你想要的东西。

(ns my.app 
    (:require [webjure.json-schema.validator :refer [validate]] 
      [cheshire.core :as cheshire])) 

    ;;; then in some function 
    (validate (cheshire/parse-string json-schema) 
       (cheshire/parse-string json-data)) 
+0

我已经简要介绍了json-schema。没有找到任何复杂类型的支持,以及解码。 相反,它使用上面显示的cheshire/parse-string来解码json,所以它只是复杂类型的字符串表示。 – lllShamanlll