August 28, 2023

On Monday, 28 August 2023 at 19:07:39 UTC, user1234 wrote:

>

On Sunday, 27 August 2023 at 19:39:05 UTC, GrimMaple wrote:

>

[...]
I tried to make it as universal as I could, but any suggestions are welcome for a discussion.

I had a quick look yesterday. One thing I have noticed is that virtual setter/getters dont seem to be supported.

I took a quick look and I don't think I fully understood what you meant. Meanwhile, I made a small snippet of how I understood your point, here's an example:

@safe unittest
{
    static class A
    {
        @serializable int b() @safe { return 0; }
    }

    static class B : A
    {
        override int b() @safe { return 1; }
    }

    B b = new B();

    assert(serializeToJSONString(cast(A)b) == `{"b":1}`);
}

I don't know if it's what you expected, but this unittest passes.

August 29, 2023

On Monday, 28 August 2023 at 19:18:17 UTC, GrimMaple wrote:

>

On Monday, 28 August 2023 at 19:07:39 UTC, user1234 wrote:

>

On Sunday, 27 August 2023 at 19:39:05 UTC, GrimMaple wrote:

>

[...]
I tried to make it as universal as I could, but any suggestions are welcome for a discussion.

I had a quick look yesterday. One thing I have noticed is that virtual setter/getters dont seem to be supported.

I took a quick look and I don't think I fully understood what you meant. Meanwhile, I made a small snippet of how I understood your point, here's an example:

@safe unittest
{
    static class A
    {
        @serializable int b() @safe { return 0; }
    }

    static class B : A
    {
        override int b() @safe { return 1; }
    }

    B b = new B();

    assert(serializeToJSONString(cast(A)b) == `{"b":1}`);
}

I don't know if it's what you expected, but this unittest passes.

@safe unittest
{
    static class A
    {
        @serializable int b() @safe { return 0; }
    }

    static class B : A
    {
        override int b() @safe { return 1; }
    }

    A o = new B(); // for o.b serialialize 1, not 0
}
August 30, 2023

On Sunday, 27 August 2023 at 19:39:05 UTC, GrimMaple wrote:

>

Hello everyone! When my https://github.com/dlang/phobos/pull/8662 predictably failed, I moved on to create a common serialization library instead that could later on be included in phobos. So I would like to request a review from you to get it to a decent state. If interested, you can find the code here, and if you want to use it with dub you can use "mud": "~>0.3.0".

I've not been very good with follow-thru, but I thought it more important phobos provide standard attributes over serialization.

https://github.com/JesseKPhillips/DIPs/blob/serialize/attribute/DIPs/1NNN-jkp.md

I actually started trying to implement the thoughts, though that proved to not have enough time.


I'm of the opinion serialize by default is better, not because it is good for defining contracts but because it is a good way to get info on a class and reduce barrier to entrance. Outside of old school xml serialization nobody is making libraries opt in.

August 30, 2023

https://code.dlang.org/packages/asdf

I have used this package in a past project and works well for both serialize and deserialize. Makes use of UDA, etc.

Just throwing it out there in case you are not aware -- there could be some niceties in there to help with the development of mud. asdf seems to be focused purely on json, though.

To have mud be supported for many formats would be great! Xml, Bson, etc.
Looking at the code, I guess thats the direction you are heading. Nice!

On Monday, 28 August 2023 at 07:59:17 UTC, GrimMaple wrote:

>

Because on practice, you might want to leave some of the stuff unserialized. It's generally better (IMO) to specifically mark serializable fields. It also allows serializaing / deserializing properties and getters / setters.

I personally am not bothered whichever route mud goes regarding rules on "serialized by default"

However, I wonder if it is worth reviewing most json libraries not just in Dlang - but in various popular languages (C++, Go, etc).

If 90% are serializing all by default (generally speaking in that lang) I don't think D should try to be different.

asdf above, for example, exports all public members by default.. and can exclude using @serdeIgnore.

In C#, the newtonsoft library exports all public members. You can exclude using [JsonIgnore]

1 2
Next ›   Last »