| Maintainer | Toshio Ito <debug.ito@gmail.com> |
|---|---|
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Greskell.GraphSON
Description
- data GraphSON v = GraphSON {}
- class GraphSONTyped a where
- nonTypedGraphSON :: v -> GraphSON v
- typedGraphSON :: GraphSONTyped v => v -> GraphSON v
- typedGraphSON' :: Text -> v -> GraphSON v
- parseTypedGraphSON :: (GraphSONTyped v, FromJSON v) => Value -> Parser (GraphSON v)
- data GValue
- data GValueBody
- nonTypedGValue :: GValueBody -> GValue
- typedGValue' :: Text -> GValueBody -> GValue
- class FromGraphSON a where
- data Parser a :: * -> *
- parseEither :: FromGraphSON a => GValue -> Either String a
- parseUnwrapAll :: FromJSON a => GValue -> Parser a
- parseUnwrapList :: (IsList a, i ~ Item a, FromGraphSON i) => GValue -> Parser a
- (.:) :: FromGraphSON a => HashMap Text GValue -> Text -> Parser a
- parseJSONViaGValue :: FromGraphSON a => Value -> Parser a
GraphSON
Wrapper for "typed JSON object" introduced in GraphSON version 2. See http://tinkerpop.apache.org/docs/current/dev/io/#graphson
This data type is useful for encoding/decoding GraphSON text.
>>>Aeson.decode "1000" :: Maybe (GraphSON Int32)Just (GraphSON {gsonType = Nothing, gsonValue = 1000})>>>Aeson.decode "{\"@type\": \"g:Int32\", \"@value\": 1000}" :: Maybe (GraphSON Int32)Just (GraphSON {gsonType = Just "g:Int32", gsonValue = 1000})
Note that encoding of the "g:Map" type is inconsistent between GraphSON v1 and v2, v3. To handle the encoding, use Data.Greskell.GMap.
Constructors
| GraphSON | |
Instances
| Functor GraphSON Source # | |
| Foldable GraphSON Source # | |
| Traversable GraphSON Source # | |
| Eq v => Eq (GraphSON v) Source # | |
| Ord v => Ord (GraphSON v) Source # | |
| Show v => Show (GraphSON v) Source # | |
| Generic (GraphSON v) Source # | |
| Hashable v => Hashable (GraphSON v) Source # | Since: 0.1.2.0 |
| ToJSON v => ToJSON (GraphSON v) Source # | If |
| FromJSON v => FromJSON (GraphSON v) Source # | If the given |
| type Rep (GraphSON v) Source # | |
class GraphSONTyped a where Source #
Types that have an intrinsic type ID for gsonType field.
Minimal complete definition
Instances
| GraphSONTyped Char Source # | |
| GraphSONTyped Double Source # | |
| GraphSONTyped Float Source # | |
| GraphSONTyped Int8 Source # | Map to "gx:Byte". Note that Java's Byte is signed. |
| GraphSONTyped Int16 Source # | |
| GraphSONTyped Int32 Source # | |
| GraphSONTyped Int64 Source # | |
| GraphSONTyped Scientific Source # | Map to "g:Double". |
| GraphSONTyped IntSet Source # | Since: 0.1.2.0 |
| GraphSONTyped [a] Source # | |
| GraphSONTyped (IntMap v) Source # | Since: 0.1.2.0 |
| GraphSONTyped (Seq a) Source # | Since: 0.1.2.0 |
| GraphSONTyped (Set a) Source # | Since: 0.1.2.0 |
| GraphSONTyped (HashSet a) Source # | |
| GraphSONTyped (Vector a) Source # | Since: 0.1.2.0 |
| (GraphSONTyped a, GraphSONTyped b) => GraphSONTyped (Either a b) Source # | Since: 0.1.2.0 |
| GraphSONTyped (HashMap k v) Source # | |
| GraphSONTyped (Map k v) Source # | Since: 0.1.2.0 |
| GraphSONTyped (GMapEntry k v) Source # | Map to "g:Map". |
| GraphSONTyped (GMap c k v) Source # | Map to "g:Map". |
| GraphSONTyped (FlattenedMap c k v) Source # | Map to "g:Map". |
constructors
nonTypedGraphSON :: v -> GraphSON v Source #
typedGraphSON :: GraphSONTyped v => v -> GraphSON v Source #
Create a GraphSON with its type ID.
>>>typedGraphSON (10 :: Int32)GraphSON {gsonType = Just "g:Int32", gsonValue = 10}
typedGraphSON' :: Text -> v -> GraphSON v Source #
Create a GraphSON with the given type ID.
>>>typedGraphSON' "g:Int32" (10 :: Int)GraphSON {gsonType = Just "g:Int32", gsonValue = 10}
parser support
parseTypedGraphSON :: (GraphSONTyped v, FromJSON v) => Value -> Parser (GraphSON v) Source #
Parse GraphSON v, but it checks gsonType. If gsonType is
Nothing or it's not equal to gsonTypeFor, the Parser fails.
GValue
An Aeson Value wrapped in GraphSON wrapper type. Basically
this type is the Haskell representaiton of a GraphSON-encoded
document.
This type is used to parse GraphSON documents. See also
FromGraphSON class.
Since: 0.1.2.0
Instances
| Eq GValue Source # | |
| Show GValue Source # | |
| Generic GValue Source # | |
| Hashable GValue Source # | |
| ToJSON GValue Source # | Reconstruct |
| FromJSON GValue Source # | Parse |
| FromGraphSON GValue Source # | |
| type Rep GValue Source # | |
data GValueBody Source #
Constructors
| GObject !(HashMap Text GValue) | |
| GArray !(Vector GValue) | |
| GString !Text | |
| GNumber !Scientific | |
| GBool !Bool | |
| GNull |
Instances
constructors
nonTypedGValue :: GValueBody -> GValue Source #
Create a GValue without "@type" field.
Since: 0.1.2.0
Arguments
| :: Text | "@type" field. |
| -> GValueBody | |
| -> GValue |
Create a GValue with the given "@type" field.
Since: 0.1.2.0
FromGraphSON
class FromGraphSON a where Source #
Types that can be constructed from GValue. This is analogous to
FromJSON class.
Instances of basic types are implemented based on the following rule.
- Simple scalar types (e.g.
IntandText): useparseUnwrapAll. - List-like types (e.g.
[],VectorandSet): useparseUnwrapList. - Map-like types (e.g.
HashMapandMap): parse intoGMapfirst, then unwrap theGMapwrapper. That way, all versions of GraphSON formats are handled properly. - Other types: see the individual instance documentation.
Note that Char does not have FromGraphSON instance. This is
intentional. As stated in the document of
AsIterator, using String in greskell
is an error in most cases. To prevent you from using String,
Char (and thus String) don't have FromGraphSON instances.
Since: 0.1.2.0
Minimal complete definition
Methods
parseGraphSON :: GValue -> Parser a Source #
Instances
parser support
A JSON parser.
parseEither :: FromGraphSON a => GValue -> Either String a Source #
Parse GValue into FromGraphSON.
Since: 0.1.2.0
parseUnwrapAll :: FromJSON a => GValue -> Parser a Source #
Unwrap the given GValue with unwrapAll, and just parse the
result with parseJSON.
Useful to implement FromGraphSON instances for scalar types.
Since: 0.1.2.0
parseUnwrapList :: (IsList a, i ~ Item a, FromGraphSON i) => GValue -> Parser a Source #
Extract GArray from the given GValue, parse the items in the
array, and gather them by fromList.
Useful to implement FromGraphSON instances for IsList types.
Since: 0.1.2.0
(.:) :: FromGraphSON a => HashMap Text GValue -> Text -> Parser a Source #
Like Aeson's .:, but for FromGraphSON.
Since: 0.1.2.0
parseJSONViaGValue :: FromGraphSON a => Value -> Parser a Source #
Implementation of parseJSON based on parseGraphSON. The input
Value is first converted to GValue, and it's parsed to the
output type.
Since: 0.1.2.0