Data.Row.Aeson

lsp-types-2.3.0.1: Haskell library for the Microsoft Language Server Protocol, data types

Safe Haskell | None
Language | GHC2021

Data.Row.Aeson

Contents

- Orphan instances

Description

This module defines orphan `aeson` instances for `Row`. They differ from the instances in `row-types-aeson` in one crucial respect: they serialise `Nothing` fields by *omitting* them in the resulting object, and parse absent fields as `Nothing`. `aeson` can be configured to have this behviour for instances for datatypes, but we want to do this for record types generically.

This is crucial to match what LSP clients expect.

Synopsis

- class ToJSONEntry a where
  - toJSONEntry :: String -> a -> Object
- class FromJSONEntry a where
  - parseJSONEntry :: Object -> String -> Parser a
- lazyUncons :: forall (l :: Symbol) (r :: Row Type). KnownSymbol l => Label l -> Rec r -> (Rec (r .- l), r .! l)

# Documentation

class ToJSONEntry a where #

Serialise a value as an entry in a JSON object. This allows customizing the behaviour in the object context, in order to e.g. omit the field.

Methods

toJSONEntry :: String -> a -> Object #

#### Instances

Instances details

ToJSON a => ToJSONEntry a # |
Instance details Defined in Data.Row.Aeson Methods toJSONEntry :: String -> a -> Object #
ToJSON a => ToJSONEntry (Maybe a) # |
Instance details Defined in Data.Row.Aeson Methods toJSONEntry :: String -> Maybe a -> Object #

class FromJSONEntry a where #

Methods

parseJSONEntry :: Object -> String -> Parser a #

#### Instances

Instances details

FromJSON a => FromJSONEntry a # |
Instance details Defined in Data.Row.Aeson Methods parseJSONEntry :: Object -> String -> Parser a #
FromJSON a => FromJSONEntry (Maybe a) # |
Instance details Defined in Data.Row.Aeson Methods parseJSONEntry :: Object -> String -> Parser (Maybe a) #

lazyUncons :: forall (l :: Symbol) (r :: Row Type). KnownSymbol l => Label l -> Rec r -> (Rec (r .- l), r .! l) #

# Orphan instances

(AllUniqueLabels r, Forall r FromJSONEntry) => FromJSON (Rec r) # |
Instance details Methods parseJSON :: Value -> Parser (Rec r) # parseJSONList :: Value -> Parser [Rec r] # omittedField :: Maybe (Rec r) #
Forall r ToJSONEntry => ToJSON (Rec r) # |
Instance details Methods toJSON :: Rec r -> Value # toEncoding :: Rec r -> Encoding # toJSONList :: [Rec r] -> Value # toEncodingList :: [Rec r] -> Encoding # omitField :: Rec r -> Bool #