- 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
- 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, FromJson a, TranslateField 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
This method defines the mapping from Haskell record field names to JSON object field names. The default is to strip 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 certain aspects of the way in which Haskell types are serialized to JSON.
exclude :: a -> String -> BoolSource
Applies to record types only. You can specialize this method to prevent certain fields from being serialized. Given a Haskell field name, it should return True if that field is to be serialized, and False otherwise.
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
This function is used as the the implementation of toJson
for the
generic instance declaration.
It's useful to be able to use the same implentation for
other instance declarations which override the default implementations
of other methods of the ToJson class.
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 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
fromJson :: a -> JsonData -> Either String aSource
objectDefaults :: a -> Map String JsonDataSource
To specify default values for the 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, FromJson a, TranslateField 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.
firstCharToUpper :: String -> StringSource
Converts the first character of a string to upper case.
firstCharToLower :: String -> StringSource
Converts the first character of a string to lower case.
This type can be used for merging two or more records together into a single JSON object. By default, a structure such as (Union X Y) is serialized as follows. First, X and Y are serialized, and a runtime error is signalled if the result of serialization is not a JSON object in both cases. The key/value pairs of the two JSON objects are then merged to form a single object.
Union a b |
Typeable2 Union | |
(Data ctx a[a28u], Data ctx b[a28v], Sat (ctx (Union a[a28u] b[a28v]))) => Data ctx (Union a[a28u] b[a28v]) | |
(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) |