Giter Club home page Giter Club logo

Comments (4)

Crell avatar Crell commented on June 5, 2024

Greetings.

There's two parts here.

  1. Numeric dictionaries should be allowed. I actually had that mostly done in a branch where I was working on allowing dictionaries to restrict their key type. Thanks for the reminder. 😄 I've finished that and merged it to master, so that should work as of the next release. (Or run dev-master for the moment.)

  2. Serializing arrays of objects is on the todo list, but not yet supported. Mainly, I'm not sure if the best way to do it. It may be a separate "entry point" object, like SerdeList or something. It also ties into the desire for streaming support. I'm still unsure of the best way to do it, which is why I haven't done it yet.

from serde.

Physikbuddha avatar Physikbuddha commented on June 5, 2024

I'm using dev-master with my array-wrapper class now, and everything's working great and smooth.
And honestly, the additional wrapper class is not too much of a hassle. Great to hear that array serialization is on the todo list, but no need to rush the features.

Thanks for the library and the quick response, Larry. ❤

from serde.

Crell avatar Crell commented on June 5, 2024

I just tagged 0.5.0, so you should be safe to switch to that now.

from serde.

ryium avatar ryium commented on June 5, 2024

As of 0.5.0, a simple way to deserialize objects in an array is described below.

class Human {
  public int $height;
  public int $weight;
}

class HumanList {
  /** @var array<Human> */
  #[Field(flatten: true)]
  #[SequenceField(arrayType: Human::class)]
  public readonly array $human;
}

$json = <<<JSON
[
  {
    "height": 172,
    "weight": 67
  },
  {
    "height": 152,
    "weight": 51
  }
]
JSON;

$serde = new SerdeCommon();

/** @var HumanList $humanList */
$humanList = $serde->deserialize($json, from: "json", to: HumanList::class);

foreach ($humanList->human as $humanArray) {
  /** @var Human $human */
  $human = $serde->deserialize($humanArray, from: "array", to: Human::class);
  // code...
}

from serde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.