Skip to content

omitNothingFields not used in Generic Decode #571

Closed

Description

@arianvp

omitNothingFields option is used for generic encoding, but it is not used for generic decoding. Is this a bug?

Activity

  1. bergmark commented on Jul 26, 2017

    @bergmark
    Collaborator

    Yes that sounds like a bug. Are you able to provide a reproduction?

  2. Lysxia commented on Jul 30, 2017

    @Lysxia
    Collaborator
    > import Data.Aeson
    > data F = F { a :: Maybe Int, b :: Maybe Int } deriving (Show, GHC.Generics.Generic)
    > instance FromJSON F where parseJSON = genericParseJSON defaultOptions
    > -- omitNothingFields = False by default
    > decode "{}" :: Maybe F
    Just (F {a = Nothing, b = Nothing})
    

    I guess we want that to fail?

  3. bergmark commented on Aug 2, 2017

    @bergmark
    Collaborator

    Whoops big typo in my deleted comment! I'm not sure if we should consider this a bug as

    > eitherDecode "{\"a\":null,\"b\":null}" :: Either String F
    Right (F {a = Nothing, b = Nothing})
    

    Does it hurt that parsing is more lenient?

  4. bergmark commented on Jun 14, 2020

    @bergmark
    Collaborator

    Coming back to this, I think it's a good thing that parsing is more lenient. I'd be open to add this as a part of Options so you can opt-in if you want it.

  5. self-assigned this
    on Jun 12, 2023
  6. phadej commented on Jun 12, 2023

    @phadej
    Collaborator

    With #1039 this will fail.

    I will first add a test to master to see how things work now, and then decide what to do in #1039.

  7. added 2 commits that reference this issue on Jun 13, 2023
  8. phadej commented on Jun 14, 2023

    @phadej
    Collaborator

    #1039 will add allowOmittedFields option (True by default) to control whether omitted fields are ok when parsing.

  9. added 4 commits that reference this issue on Jun 15, 2023
    3797f8f
    d835b9d
    f0c4476
    b06eb2c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions