Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Add CE Builder for Json erased types (as they are not records and with is missing) #1425

Open
jkone27 opened this issue Jan 24, 2022 · 5 comments

Comments

@jkone27
Copy link

jkone27 commented Jan 24, 2022

Would be pretty useful to have CE builders for erased type, e.g. JsonProvider provided types, as they are immutable and using the full constructor is annoying especially for big objects...

type MyProvidedType = 
   JsonProvider<"""{ "name" : "hello", "test" : { "nested" : true }} """>

instead of

let myJsonValue = new MyJsonProvider
   .Root(name="test", new MyJsonProvider.Nester(false)) 
   // quickly becomes cumbersome for big object hierarchies! try with a big json file

do..

let my_provided_ce = MyProvidedType.Builder()

let myJsonValue = // MyProvidedType.Root 
     my_provided_ce {   // uses Sample as base for builder
         name "test" 
    }
    
let myOtherValue =  // MyProvidedType.Root 
     my_provided_ce {   // uses Sample as base for builder
         test {
            nested false
         }
    }
@cartermp
Copy link
Collaborator

@jkone27 would you be interested in submitting a PR with a proposed implementation?

@jkone27
Copy link
Author

jkone27 commented Jan 24, 2022

i could give it a try but i have not much idea where to start 😆, i did this (see below) once to add "copy mutation" to JsonProvider erased type, but ofc it's quite hacky and messy...

https://github.com/jkone27/FSharp.Data.Mutator

so i thought a similar approach could make it easier to work with and maybe useful in general for other erased types too?
will try to checkout the repo as a start 👍

@jkone27
Copy link
Author

jkone27 commented Jan 24, 2022

In the topic of possibly extending Fsharp.Data, which one would be the easiest option between these as per implementation ? Pros/cons/possible

  1. Allow JsonValue setters in generated types making them mutable (is it possible with erased types?) trike passing allowMutableProperties in the constructor of the provider
  2. Somehow generate record types instead of current types, as they have already the with copy mutator construct built in… (not sure if it’s feasible)
  3. Adding the CEs as proposed in the current approach (would it be for all types in Helper.fs ???

@jkone27
Copy link
Author

jkone27 commented Jan 24, 2022

as per option 3 (add a CEs for generated types), should it be done in Helper.fs around here?
image

or here but then i guess it becomes something more specific, like each provider needs to add the extra CE builder to constructor..

image

@jkone27
Copy link
Author

jkone27 commented Jan 24, 2022

one way i could add an optional setter code, this wouldn't require the overcomplication of adding the CEs methods (with CustomOperationAttribute) maybe...
could be done in JsonGenerator.fs

(https://gist.github.com/odytrice/313b2107f6ad52de12ae89f35941d4b2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants