Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Nicer deserializer format #7

Closed
davidmorgan opened this issue Dec 8, 2015 · 8 comments
Closed

Nicer deserializer format #7

davidmorgan opened this issue Dec 8, 2015 · 8 comments

Comments

@davidmorgan
Copy link
Contributor

Can use an iterator instead of one for loop and a bool to switch between keys and values.

@Andersmholmgren
Copy link

Not sure exactly what you are referring to here. I'm looking for a serializer format that is more the typical looking json formatting.

My current use case is that I am building BuiltValue classes to represent Json Schema.
I need to be able to serialize/ deserialize from regular json schema documents.

Of course for interoperability with external sources of JSON this is needed too.

If this is not what you are referring to then I'll likely need to look at building something. In which case I'd like your thoughts on whether it makes sense to leverage the code in this repo or not

@davidmorgan
Copy link
Contributor Author

This issue is just about how the generated code works.

Re: the wire format itself, it's designed for use in RPCs. It's unlikely to match any other specific format. Although, if there's an existing format that happens to cover what's needed, we could switch.

One consideration for example is whether to use a map from field name to field value. This looks nicer. But, it's a lot more expensive than an array, in memory and performance. So in this context arrays are better.

@Andersmholmgren
Copy link

Yeah makes sense for RPCs if you control both ends of the channel.

In many cases you don't though and the map based way seems to be the norm.

I'll play around with generating some Codecs

@davidmorgan
Copy link
Contributor Author

Right.

I would be fine with supporting multiple formats; if it's an option at code generation time then this wouldn't add any runtime/compile overhead. But there'd need to be a clear use case for each format, of course.

Could you point to a specification of the format you're interested in, please?

@Andersmholmgren
Copy link

Not sure what you are after in terms of specifications. If you mean a spec for how a dart class should be serialized to JSON then I don't think such a spec exists.

However, I am working on is a built_value representation of json schema.

So this built_value class is intended to be a faithful reproduction of the core schema.

I'm also working on a transformation framework and with that I'll create a bidirectional transformation between Json Schema and a Built Value model. So that will allow me to generate dart classes from a json schema and vice versa.

It would be use a 'typical' representation of json. e.g a class like

abstract class Person implements Built<Person, PersonBuilder> {
  String get name;
  int get age;
 ...
}

would serialise like

{
  "name": "fred",
  "age": 15
}

In cases where you have subtypes that can be deserialized into then it'll likely need a field that identifies the type.

Does that make sense?

@Andersmholmgren
Copy link

http://json-schema.org/example2.html contains an example json schema. I need to be able to serialize/deserialize these examples to/from instances of the Schema class.

Also http://json-schema.org/schema is another example. It is just json schema represented as json schema

@davidmorgan
Copy link
Contributor Author

This issue moved to

Nicer generator code: google/built_value.dart#64
Nicer JSON: google/built_value.dart#65

@davidmorgan
Copy link
Contributor Author

FYI this is now happening over at

google/built_value.dart#65

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

No branches or pull requests

2 participants