Giter VIP home page Giter VIP logo

Comments (2)

droyo avatar droyo commented on July 29, 2024

This is tricky, because the original struct is embedded in the layout struct:

		var layout struct{
			*T
			{{- range .Overrides}}
			{{.FieldName}} *{{.ToType}}`+"`{{.Tag}}`"+`
			{{end -}}
		}

The most straightforward way I can see to preserve order is to do away with the embedding, name each field of the layout struct with the appropriate type, and essentially copy the original type by assigning to each field.

This will make the MarshalXML functions for large structs very long, as it will require at least two lines per field. I could use the reflect package to reduce it, but I was hoping to avoid that.

from go-xml.

markfarnan avatar markfarnan commented on July 29, 2024

I had this problem also.

Solution was I changed the type in the struct from time.Time to xsdDateTime, and now this just uses the custom marshal/unmarshal interface on that type directly, rather than going through a layout stuff for the higher level struct.

Unclear if I've caused some edge case or not, but so far it appears to work just fine, and order is preserved.

It does mean I have to type override it when using the struct, but that's fine for my usecase.

from go-xml.

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.