Git Product home page Git Product logo

Comments (12)

JakeWharton avatar JakeWharton commented on July 26, 2024 1

from auto-value-moshi.

rharter avatar rharter commented on July 26, 2024

Honestly I don't even know what Types.newParameterizedTypeWithOwner is. @swankjesse or @JakeWharton, any insight?

from auto-value-moshi.

NightlyNexus avatar NightlyNexus commented on July 26, 2024

It's for nested types.

class Foo {
  class Bar<T> {
  }
}
Types.newParameterizedTypeWithOwner(Foo.class, Bar.class, String.class)

so it depends on where the A, B, C classes are nested.

from auto-value-moshi.

nedtwigg avatar nedtwigg commented on July 26, 2024

Aha! That explains it. Sorry, my <A<B<C<Long>>>> didn't capture all of the relevant info. Great inference! Two surprising things:

  1. the classes in question are all static. so it's:
class Foo {
  static class Bar<T> {
  1. the owner types that I supplied are all wrong, but it works.

The constructor of ParameterizedTypeImpl requires an owner type for static inner classes, but doesn't care if it's the right class or not. I've spent the whole day showing the moshi team that I don't understand what's going on ;-) But this seems a bit off. Either ParameteredTypeImpl shouldn't need an owner class for static enclosed classes (seems right to me), or if it's gonna require an owner, maybe it oughtta check that it's the right owner?

from auto-value-moshi.

NightlyNexus avatar NightlyNexus commented on July 26, 2024

If you pass in the wrong owner type, you will get subtle errors when checking equality of Types.
Good spot; I opened square/moshi#450 to fail explicitly and earlier in the common case.

from auto-value-moshi.

nedtwigg avatar nedtwigg commented on July 26, 2024

So if a type is nested (which we can check with Class.getEnclosingType) then we should create it with Types.newParameterizedTypeWithOwner rather than Types.newParameterizedType. I'd be happy to provide a PR, but I'm stuck on an old version by #99. I'll stay subbed, in case we figure out a way to resolve #99.

from auto-value-moshi.

ZacSweers avatar ZacSweers commented on July 26, 2024

Is this actually something we should support? As opposed to just saying the inner classes should also be static. Thinking out loud, but it it seems weird to me that a subset of the nested json data would have any requirements of the java ownership of the class consuming it. I'm kind of in favor of voting just requiring inner classes to be static (with a descriptive error), but open to hear arguments in favor of non-static inner classes

from auto-value-moshi.

nedtwigg avatar nedtwigg commented on July 26, 2024

I agree that only supporting static inner classes is the right call. However, inner classes of any kind currently not supported, static or not.

from auto-value-moshi.

ZacSweers avatar ZacSweers commented on July 26, 2024

Isn't newParameterizedTypeWithOwner only for non-static inner classes?

from auto-value-moshi.

nedtwigg avatar nedtwigg commented on July 26, 2024

That was not my experience.

from auto-value-moshi.

NightlyNexus avatar NightlyNexus commented on July 26, 2024

Isn't newParameterizedTypeWithOwner only for non-static inner classes?

No. It's for nested classes.

from auto-value-moshi.

ZacSweers avatar ZacSweers commented on July 26, 2024

I'm using newParameterizedTypeWithOwner without issue here: 1c5e6f8

As such I'm going to close this as static inner classes do work

from auto-value-moshi.

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.