How to deserializes into generic struct that includes element name

Open
#778 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
backend

Research direction

Start by reading the deserialization code and tests for mapping XML elements into structs; the issue does not name specific files or tests. Check whether the element name can be exposed as a field while preserving generic deserialization, then add a focused test using a MaterialX style node graph. Done means the deserialized node retains its element name and the test passes.

Written by the indexing model from the issue text.

Description

serde

I'm trying to parse MaterialX files like this one. They include "node graphs" which are a list of different elements with quite similar attributes and child elements.

As I don't know what elements to expect up front (they can be defined by external definition files), my idea was to have a generic Node struct and deserialize into that and then process it at a later stage. This works -- but I lose access to the element name. Is there a way to add it in as a field, e.g. using #[serde(rename = "$element-name")]?

If you can point me at the right place I'd be happy to make a PR.

Dominant language
Rust
Stars
1.6k
Forks
299
Avg merge
2d 4h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tafia/quick-xml

All issues in tafia/quick-xml

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.