Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unexpected Haskell Aeson warning: No explicit implementation for 'toJSON"

Tags:

haskell

aeson

I am trying to use the aeson library for json parsing and I am following the documentation. This is my code right now:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}

import Data.Aeson as Ae
import Data.Text  as T
import qualified Data.ByteString.Lazy as BS
import GHC.Generics

data Episode = Episode { season :: Int
                       , epNum  :: Int
                       } deriving (Show, Generic)

data Series = Series { title      :: !T.Text
                     , curEpisode :: Episode
                     } deriving (Show, Generic)

instance FromJSON Episode
instance ToJSON Episode          -- Warning here
instance FromJSON Main.Series
instance ToJSON Main.Series      -- Warning here

The problem is that I get those two warnings:

src\Main.hs:21:10: Warning:
    No explicit implementation for
      `toJSON'
    In the instance declaration for `ToJSON Episode'

src\Main.hs:22:10: Warning:
    No explicit implementation for
      `toJSON'
    In the instance declaration for `ToJSON Main.Series'

I can't figure out why is this happening.

EDIT:

GHC Version: 7.10.2

aeson version: 0.10.0.0 (latest)

like image 954
TheCrafter Avatar asked Oct 09 '15 18:10

TheCrafter


1 Answers

I can work around the warnings by doing this:

instance FromJSON Episode
instance ToJSON Episode where
  toJSON = genericToJSON defaultOptions
instance FromJSON Main.Series
instance ToJSON Main.Series where
  toJSON = genericToJSON defaultOptions

I still don't know why the warnings are there but I saw there is already a bug report on github.

like image 108
TheCrafter Avatar answered Oct 24 '22 05:10

TheCrafter