- class TranslateField a where
- translateField :: a -> String -> String
- data TranslateFieldD a
- class TranslateField a => ToJson a where
- toJson :: a -> JsonData
- exclude :: a -> String -> Bool
- arrayPrepend :: a -> [JsonData]
- arrayAppend :: a -> [JsonData]
- objectExtras :: a -> [(String, JsonData)]
- data ToJsonD a
- genericToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => a -> JsonData
- enumToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => (String -> String) -> a -> JsonData
- data JsonData
- class TranslateField a => FromJson a where
- objectDefaults :: a -> Map String JsonData
- data FromJsonD a
- parseJsonString :: String -> Either String JsonData
- parseJsonByteString :: ByteString -> Either String JsonData
- fromJsonString :: FromJson a => a -> String -> Either String a
- fromJsonByteString :: FromJson a => a -> ByteString -> Either String a
- genericFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => a -> JsonData -> Either String a
- enumFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => (String -> String) -> a -> JsonData -> Either String a
- stripInitialUnderscores :: [Char] -> [Char]
- toJsonString :: ToJson a => a -> String
- firstCharToUpper :: String -> String
- firstCharToLower :: String -> String
- data Union a b = Union a b
- type Union3 a b c = Union (Union a b) c
- type Union4 a b c d = Union (Union3 a b c) d
- type Union5 a b c d e = Union (Union4 a b c d) e
- type Union6 a b c d e f = Union (Union5 a b c d e) f
- type Union7 a b c d e f g = Union (Union6 a b c d e f) g
- type Union8 a b c d e f g h = Union (Union7 a b c d e f g) h
- type Union9 a b c d e f g h i = Union (Union8 a b c d e f g h) i
- type Union10 a b c d e f g h i j = Union (Union9 a b c d e f g h i) j
Documentation
class TranslateField a whereSource
translateField :: a -> String -> StringSource
By default, Haskell record field names are converted into JSON object field names by stripping any initial underscores. Specialize this method to define a different behavior.
Typeable a => TranslateField a | Removes initial underscores from a string. |
data TranslateFieldD a Source
TranslateField t => Sat (TranslateFieldD t) |
class TranslateField a => ToJson a whereSource
New instances can be added to this class to customize JSON serialization.
exclude :: a -> String -> BoolSource
You can specialize this method to prevent fields from being serialized. The method should return a list of the Haskell names of the fields to be excluded.
arrayPrepend :: a -> [JsonData]Source
Types that will be converted to JSON arrays can override this method to specify additional elements to be prepended to the array.
arrayAppend :: a -> [JsonData]Source
Types that will be converted to JSON arrays can override this method to specify additional elements to be appended to the array.
objectExtras :: a -> [(String, JsonData)]Source
Types that will be converted to JSON objects can override this method to specify additional fields of the object.
genericToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => a -> JsonDataSource
enumToJson :: (Data ToJsonD a, ToJson a, TranslateField a) => (String -> String) -> a -> JsonDataSource
This function can be used as an implementation of toJson
for simple enums.
It just converts an enum value to a string determined by the name of the constructor,
after being fed through the (String -> String) function given as the first argument.
A Haskell representation of a JSON data structure.
class TranslateField a => FromJson a whereSource
objectDefaults :: a -> Map String JsonDataSource
In order to specify default values for required fields of a JSON object, specialize this method in the instance definition for the relevant datatype.
parseJsonString :: String -> Either String JsonDataSource
Converts a String (interpreted as a true unicode String) to an instance of JsonData.
parseJsonByteString :: ByteString -> Either String JsonDataSource
Converts a ByteString to an instance of JsonData (unicode encoding is detected automatically).
fromJsonString :: FromJson a => a -> String -> Either String aSource
Converts a JSON String (interpreted as a true unicode string) to a value of the type given by the first (dummy) argument.
fromJsonByteString :: FromJson a => a -> ByteString -> Either String aSource
Converts a JSON ByteString (with unicode encoding automatically detected) to a value of the type given by the first (dummy) argument.
genericFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => a -> JsonData -> Either String aSource
enumFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => (String -> String) -> a -> JsonData -> Either String aSource
The counterpart of enumToJson
.
stripInitialUnderscores :: [Char] -> [Char]Source
toJsonString :: ToJson a => a -> StringSource
Converts a value to an ASCII-only JSON String.
Use this for merging two or more records together. Sensible instances of FromJson and ToJson are already defined for this type.
Union a b |
Typeable2 Union | |
(Data ctx a[a28s], Data ctx b[a28t], Sat (ctx (Union a[a28s] b[a28t]))) => Data ctx (Union a[a28s] b[a28t]) | |
(Show a, Show b) => Show (Union a b) | |
(ToJson a, ToJson b, TranslateField a, TranslateField b, Typeable a, Typeable b, Typeable2 Union) => ToJson (Union a b) | |
(FromJson a, FromJson b, Typeable a, Typeable b, TranslateField a, TranslateField b) => FromJson (Union a b) |