gigaZhang / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

Inline Property Syntax is not as described in docs #129

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Define an inline property with only a getter
2. Orika will not treat it as inline-property

What is the expected output? What do you see instead?
Expected: Correct Mapping
Instead: Orika complains that "property:{getter()}" is not part of the mapped 
object

What version of the product are you using? On what operating system?
Orika 1.4.3

Please provide any additional information below.
I refer to the "In-line property syntax" defined in 
http://orika-mapper.github.io/orika-docs/advanced-mappings.html 

It seems that the RegEx for the inline property is broken, requiring the 
definition of a getter even if none is present.

This RegEx should be correct, making both the getter and setter optional
([\w]+)\:\{(?:\s*([\w\(\)'\"\% ]+))?\s*(?:\|\s*([\w\(\)'\"\%, 
]+)\s*)?(?:\|?\s*(?:type=)([\w.\$ \<\>]+))?\}

Original issue reported on code.google.com by l.brueni...@googlemail.com on 9 Oct 2013 at 8:57

GoogleCodeExporter commented 9 years ago
Thanks !
 (in fact they one should be required getter or setter, property without any setter or getter make no sense)

Original comment by elaat...@gmail.com on 16 Oct 2013 at 8:50

GoogleCodeExporter commented 9 years ago
Any reason this was not fixed in 1.4.5?

Original comment by l.brueni...@googlemail.com on 16 Sep 2014 at 12:37

GoogleCodeExporter commented 9 years ago
I came here seeing the same problem.

    @Test
    public void testInline() {
        Assert.assertTrue(Pattern.compile("([\\w]+)\\:\\{\\s*([\\w\\(\\)'\"\\% ]+)\\s*\\|\\s*([\\w\\(\\)'\"\\%, ]+)\\s*\\|?\\s*(?:(?:type=)([\\w.\\$ \\<\\>]+))?\\}").matcher("propName:{getInt('propName')|setInt('propName', '%s')|type=java.lang.String}").matches());
        Assert.assertTrue(Pattern.compile("([\\w]+)\\:\\{\\s*([\\w\\(\\)'\"\\% ]+)\\s*\\|\\s*([\\w\\(\\)'\"\\%, ]+)\\s*\\|?\\s*(?:(?:type=)([\\w.\\$ \\<\\>]+))?\\}").matcher("propName:{getInt('propName')|setInt('propName', '%s')}").matches());
        Assert.assertTrue(Pattern.compile("([\\w]+)\\:\\{\\s*([\\w\\(\\)'\"\\% ]+)\\s*\\|\\s*([\\w\\(\\)'\"\\%, ]+)\\s*\\|?\\s*(?:(?:type=)([\\w.\\$ \\<\\>]+))?\\}").matcher("propName:{|setInt('propName', '%s')}").matches());
        Assert.assertTrue(Pattern.compile("([\\w]+)\\:\\{\\s*([\\w\\(\\)'\"\\% ]+)\\s*\\|\\s*([\\w\\(\\)'\"\\%, ]+)\\s*\\|?\\s*(?:(?:type=)([\\w.\\$ \\<\\>]+))?\\}").matcher("propName:{getInt('propName')}").matches());
    }

First two lines pass, second two lines fail

Original comment by dodts...@gmail.com on 26 Feb 2015 at 11:26

GoogleCodeExporter commented 9 years ago
This test will pass if you update the pattern.  Updated pattern is included in 
the test.

    @Test
    public void testInline() {

        String pattern = "([\\w]+)\\:\\{(?:(?:\\s*([\\w\\(\\)'\"\\% ]+)\\s*)|(?:\\|\\s*([\\w\\(\\)'\"\\%, ]+)\\s*)){1,2}\\s*(?:(?:\\|type=)([\\w.\\$ \\<\\>]+))?\\}";
        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{getInt('propName')|setInt('propName', '%s')|type=java.lang.String}").matches());
        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{getInt('propName')|setInt('propName', '%s')}").matches());
        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{|setInt('propName', '%s')}").matches());
        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{getInt('propName')}").matches());

        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{getInt('propName')|setInt('propName', '%s')|type=java.lang.String}").matches());
        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{getInt('propName')|setInt('propName', '%s')}").matches());
        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{|setInt('propName', '%s')}").matches());

        Assert.assertFalse(Pattern.compile(pattern).matcher("propName:{}").matches());
        Assert.assertFalse(Pattern.compile(pattern).matcher("propName:{|}").matches());
        Assert.assertFalse(Pattern.compile(pattern).matcher("propName:{||}").matches());
        Assert.assertFalse(Pattern.compile(pattern).matcher("propName:{||type=}").matches());
        Assert.assertFalse(Pattern.compile(pattern).matcher("propName:{||type=java.lang.String}").matches());
        Assert.assertFalse(Pattern.compile(pattern).matcher("propName:{|type=java.lang.String}").matches());

        //False positive
        Assert.assertTrue(Pattern.compile(pattern).matcher("propName:{|setInt('propName', '%s')|setInt('propName', '%s')|type=java.lang.String}").matches());
    }

Original comment by dodts...@gmail.com on 26 Feb 2015 at 11:47

GoogleCodeExporter commented 9 years ago
Can you please make a pull request on github including the test

Original comment by elaat...@gmail.com on 27 Feb 2015 at 3:34