Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsType properties starting with dollar are not accepted #9554

Closed
marciodel opened this issue Oct 5, 2017 · 3 comments · Fixed by #9875
Closed

JsType properties starting with dollar are not accepted #9554

marciodel opened this issue Oct 5, 2017 · 3 comments · Fixed by #9875

Comments

@marciodel
Copy link

GWT version: 2.8.1
Browser (with version): N/A
Operating System: N/A


Description

GWT does not allow an @JsProperty accessor method if the property starts with '$'.

Steps to reproduce

Just try to compile:

@JsType
public class Test {
  @JsProperty
  public native String get$1();
}
Known workarounds

Must set @JsProperty name attribute to be accepted. E.g.:

  @JsProperty(name="$1")
  public static native String get$1();
Discussion

I understand this is not a priority issue, but I've just tested in the JVM using JavaBeans Introspector:

package jbeans.test;

public class TestBean {
	private String name;
	private String $dollar;
	private String _underscore;
	private String $0;
	private String $1;
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void set$dollar(String $dollar) {
		this.$dollar = $dollar;
	}
	
	public String get$dollar() {
		return $dollar;
	}
	
	public String get_underscore() {
		return _underscore;
	}
	
	public void set_underscore(String _underscore) {
		this._underscore = _underscore;
	}
	
	public void set$0(String $0) {
		this.$0 = $0;
	}
	
	public String get$0() {
		return $0;
	}
	
	public String get$1() {
		return $1;
	}
	
	public void set$1(String $1) {
		this.$1 = $1;
	}
}

package jbeans.test;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

public class Main {
	public static void main(String[] args) {
		try {
			BeanInfo beanInfo = Introspector.getBeanInfo(TestBean.class);

			for (PropertyDescriptor props : beanInfo.getPropertyDescriptors()) {
				System.out.println("Property: " + props.getName());
			}

		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

outputs:

Property: $0
Property: $1
Property: $dollar
Property: _underscore
Property: class
Property: name
@marciodel marciodel changed the title JsType properties starting with dollar are no accepted JsType properties starting with dollar are not accepted Oct 15, 2017
@aeromac
Copy link

aeromac commented Dec 12, 2023

@ is also not allowed. The MS Graph API uses @OData Json values

@niloc132
Copy link
Contributor

While $ is a valid js identifier, @ is not, and JsInterop is not intended to be a json <-> java mapper, but js <-> java. Any string could be a valid json key (including with spaces, etc), but should not be supported by jsinterop members/namespaces/types. Instead, use a tool intended for JSON de/serialization, or access properties by name (such as with JsPropertyMap.get(String key)).

@aeromac
Copy link

aeromac commented Dec 12, 2023

Thankyou for your explanation, that makes sense.

niloc132 added a commit to niloc132/gwt that referenced this issue Dec 12, 2023
The old implementation only allowed a capital letter as the first
character of a bean-like property, which isn't sufficient. Instead, we
need to support cases where the first character is *not* lower case, so
that non-letters that are valid for the first character are permitted.

Fixes gwtproject#9554
niloc132 added a commit that referenced this issue Jan 10, 2024
#9875)

The old implementation only allowed a capital letter as the first
character of a bean-like property, which isn't sufficient. Instead, we
need to support cases where the first character is *not* lower case, so
that non-letters that are valid for the first character are permitted.

Fixes #9554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants