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

Duplicated fields when java name is uppercase #1004

Open
baffelli opened this issue Aug 24, 2023 · 1 comment
Open

Duplicated fields when java name is uppercase #1004

baffelli opened this issue Aug 24, 2023 · 1 comment

Comments

@baffelli
Copy link

I observed that if I have a Java field starting with an uppercase letter (I know it is against Java conventions, but it is legal syntax nonetheless), the generated Typescript code contains duplicate fields; e.g. the following Java code:

class MyClass{
  string A
}

will give the following interface

interface MyClass{
  A: string
  a: string
}

You can test this with the following:

import ch.systemsx.cisd.base.annotation.JsonObject;
import cz.habarta.typescript.generator.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.util.List;

public class MethodExtensionTest {

    interface GenericTestClass<A> {
        A get();
    }


    class TestClass {
        public boolean A;
        public String[] B;
        public boolean getA() {return false;}
        public String[] getB() {return null;}
    }

    class NestedTestClass {
        public TestClass A;
        public boolean getA() {return false;}
    }


    final Settings settings = new Settings();
    @BeforeTest
    public void setSettings(){
        settings.outputKind = (TypeScriptOutputKind.module);
        settings.jsonLibrary = JsonLibrary.jackson2;

    }



    @Test
    public void testGenericClass() {
        final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(GenericTestClass.class));
        System.out.println(output);

    }

    @Test
    public void testNormalClass(){
        final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(TestClass.class));
        System.out.println(output);
    }

    @Test
    public void testNestedClass(){
        final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(NestedTestClass.class));
        System.out.println(output);
    }
}

The output of testNormalClass will contain both uppercase and lowercase fields "A", "a" with the same type.

@panchenko
Copy link
Contributor

Not a bug.
All the public members are included into JSON serialisation. If you don't want some of them - they should be annotated with @JsonIgnore or similar annotation.

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

No branches or pull requests

2 participants