Giter VIP home page Giter VIP logo

Comments (2)

droyo avatar droyo commented on September 4, 2024

Looking into this further, I believe I've found the issue. With the commit ed9a5b5, I used something like the following strategy to override unmarshalling for individual fields in a struct:

type T RealType
var overlay struct {
	*T
	AvailabilityStartTime *xsdDateTime `xml:"availabilityStartTime,attr,omitempty"`
}
overlay.T = (*T)(t)
overlay.AvailabilityStartTime = (*xsdDateTime)(&layout.T.AvailabilityStartTime)
return d.DecodeElement(&overlay, &start)

Notably, the local type T is used to "silence" the MarshalXML method of RealType. This lets us use all the convenient reflection in the encoding/xml package while only having to override the fields we want. Now look at this example program:

https://play.golang.org/p/0el2d1S145

In short, methods of the embedded structs are not silenced by the type T trick. As a result, in the example above, if RealType had an embedded field that had its own UnmarshalXML implementation, that method would be called instead of falling through to encoding/xml's built-in unmarshalling logic.

So, the workaround here would be to forgo struct embedding, and expand the base type that a complexType extends. The internal/dependency package could be useful here for "dereferencing" types in the correct order.

This will make the generated files larger for complex schema, and make the type hierarchy less obvious. However, I don't see a better alternative.

from go-xml.

droyo avatar droyo commented on September 4, 2024

Fixed with b12a23a

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.