json - Override how Data.Aeson handles only one field of my record -


I am making a REST API for university courses:

  data course = course Examples of JSN course from example ID: may be text, name :: text, deleted :: boom} deriving (show, generic), tojson course   

I deleted Gone to be optional in the chain JSON structure, but not in my application. I want to set to be incorrect to incorrect , if it is not specified during parsing.

I can write a manual example for FromJSON , but I do not want to write it for all areas. I want to declare how removable methods are handled and automatically handle everything in the example.

How do I do this?

There is no way for my knowledge to adapt the general example, Make a slightly different way:

  data course = course {courseId :: probably text - do not use 'id', it's already a function, name: text} Derivating (Show, Generic) Data Removable A = Delayable {Deleted: Bull, Item :: A} Deriving (example) example from JSN Cor Example ToJSON Jejesoan A = example of course gt; From JSON (deletable) where parseJSON (object v) = I IT & lt; - parseJSON (object v) D & lt; V.:? "stripped of".! = Deleting incorrect return $ D. I can parseJSON _ = major   

now you can

  & gt; No deleted = "{\" name \ ": \" Math \ ", \" courseId \ ": \" 12345 \ "}: :: text & gt; Withdeleted =" {\ "name \": \ "Math \ "," "Deleted", "Deleted": True "" Text: "Decode No Delitated :: Probably (Dletable Course) Bus (Delayable) {deleted = false, items = Course {CourseID = Just "12345", name = "Math"}}) Decode No Delayed: Perhaps Course Just (Course {CourseID = Bus "12345", Name = "Math"}); Decoding With Delayed :: Probably (Dellette Course) Bus (Delayable) {Deleted = True, Item = Course {Course Id = Just "12345", Name = "Math"}}) Jr. Decode :: Maybe Course Just (Course {CourseIID = just "12345", name = "Math"})   

And now you alternatively choose a course as a tag for DelTable You can tag it when you need it, and FromJSON examples take care of everyone.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -