Comments (16)
https://www.safaribooksonline.com/library/view/xml-schema/0596002521/re52.html
"
Description
xs:totalDigits defines the maximum number of digits of decimal and derived datatypes (both after and before the decimal point, not counting the decimal point itself).
This facet constrains the value space, which means that the number of digits is checked after the value is transformed to its canonical form and the leading and trailing zeros are removed.
"
Another example here: http://zvon.org/xxl/XMLSchemaTutorial/Output/ser_types_st3.html
With 10 reserved for the fractional part, that should leave 1 for the whole number part? Which seems to match the generated code?
from krasa-jaxb-tools.
<simpleType name="decimalType">
<restriction base="decimal">
<totalDigits value="3"/>
<fractionDigits value="2"/>
</restriction>
</simpleType>
Valid
123
123.0
123.000
12.3
1.23
Invalid
0.123
12.34
123.1
When decimals are not present then integral part is allowed to have number of digits as 'totalDigits' as per schema. But generated annotation is not going to do that if integer is (totalDigits - fractionDigits) instead totalDigits.
from krasa-jaxb-tools.
Digits supporting "total" (optional) along with integer and fraction will be helpful! But it wont come in the scope of this forum probably.
So even it's not exact fix it's good if we would have Digits:integer as decimal:totalDigits from schema definition?
from krasa-jaxb-tools.
If you can provide a github project demoing the issue I could attempt to fix with a pull-request.
Demo including:
minimal schema
generated bean
showing xsd validation passes
and hibnerate validator does not
or vice versa
from krasa-jaxb-tools.
@davidkarlsen : The github sample for above issue is available at https://github.com/akumar11/KrasaSample
from krasa-jaxb-tools.
@akumar11 Actually there seems to be an error with the test itself - when I fixed the filepaths all tests pass: https://github.com/akumar11/KrasaSample/pulls
from krasa-jaxb-tools.
By changing (correcting) test case com.test.krasa.XsdObjectValidateTest.testXsdObject we can see bug.
Modify line assertEquals(Boolean.FALSE, validateBean(travelInfoData3).isEmpty()); to assertEquals(Boolean.TRUE, validateBean(travelInfoData3).isEmpty()); then there is failure.
from krasa-jaxb-tools.
@davidkarlsen : I prepared the above sample as per Windows Environment. However, you can see @digits validation failure by changing the assertion (line#85) from Boolean.FALSE to Boolean.TRUE ( @mcmoulis explained this well in above comment ) .
from krasa-jaxb-tools.
Any comments/inputs?
from krasa-jaxb-tools.
Should I take a look? :-)
from krasa-jaxb-tools.
@krasa That would be great - I never came along for it.
from krasa-jaxb-tools.
@krasa Did you figure anything out?
from krasa-jaxb-tools.
Well, I agree that there is a bug :-)
I think the best would be to introduce a custom annotation+validator. That would require the plugin to be used also as a compile+runtime dependency (or make a new runtime library for just that, but that would be much more work).
And @digits should not be used when there are fractionDigits in xsd.
from krasa-jaxb-tools.
@krasa Could we not simply apply some simple arithmetics? When defining totalDigits and fractionDigits in the xsd world, leaving total-fraction=integer in the jsr303 world? http://zvon.org/xxl/XMLSchemaTutorial/Output/ser_types_st3.html
http://docs.oracle.com/javaee/6/api/javax/validation/constraints/Digits.html
from krasa-jaxb-tools.
aha - I see it now - that's actually what is happening - but leaves no space for the integral part when in fact no fraction digits are present
from krasa-jaxb-tools.
Super - this issue can be closed and put in the 1.4 milestone! Thanks a lot!
from krasa-jaxb-tools.
Related Issues (20)
- Plugin crashes with NPE at fields with final static (fixed value) HOT 3
- minExclusive=0, fractionDigits=2 wrong annotation HOT 1
- xs:enumeration is not translated correctly to annotations HOT 8
- Exception thrown if XSD union is used HOT 4
- XReplacePrimitives not converting doubles and floats
- Pattern Validation for enums. At the moment Krasa supports only String type for Patterns HOT 2
- Plugin throws RTE on XReplacePrimitives for serialVersionUID HOT 2
- Tagged releases HOT 1
- Do not use @Pattern.List for multiple patterns
- Further support for krasa-jaxb-tools HOT 1
- Bug in @Digits annotations HOT 1
- Multiple Patterns with own base-restriction-simpletype is ignored HOT 1
- Attributes don't seem to be annotated unless they have a minOccurs > 0 HOT 1
- 1.7 branch release HOT 1
- @Size for ArrayList/Collections/Maps
- Traversing super classes in loop iterates over wrong variable
- Enumeration pattern is not escaped HOT 2
- Wrong integral digits in Digit-Annotation in combination of totalDigits and fractionDigits in XSD HOT 1
- Is the plugin executable from cmd line without need of maven? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from krasa-jaxb-tools.