Skip to content

Commit 1978604

Browse files
committed
update Java version
1 parent 369bc12 commit 1978604

File tree

12 files changed

+783
-235
lines changed

12 files changed

+783
-235
lines changed

api/com.upokecenter.cbor.CBORObject.md

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,41 +1371,39 @@ Converts this CBOR object to an object of an arbitrary type. See the
13711371
for Plain-Old-Data deserialization, then this method checks the
13721372
given type for eligible setters as follows:</li> <li>(*) In the .NET
13731373
version, eligible setters are the public, nonstatic setters of
1374-
properties with a public, nonstatic getter. If a class has two
1375-
properties of the form "X" and "IsX", where "X" is any name, or has
1376-
multiple properties with the same name, those properties are
1377-
ignored.</li> <li>(*) In the Java version, eligible setters are
1378-
public, nonstatic methods starting with "set" followed by a
1379-
character other than a basic digit or lower-case letter, that is,
1380-
other than "a" to "z" or "0" to "9", that take one parameter. The
1381-
class containing an eligible setter must have a public, nonstatic
1382-
method with the same name, but starting with "get" or "is" rather
1383-
than "set", that takes no parameters and does not return void. (For
1384-
example, if a class has "public setValue(string)" and "public
1385-
getValue()", "setValue" is an eligible setter. However, "setValue()"
1386-
and "setValue(string, int)" are not eligible setters.) If a class
1387-
has two or more otherwise eligible setters with the same name, but
1388-
different parameter type, they are not eligible setters.</li>
1389-
<li>Then, the method creates an object of the given type and invokes
1390-
each eligible setter with the corresponding value in the CBOR map,
1391-
if any. Key names in the map are matched to eligible setters
1392-
according to the rules described in the <code>PODOptions</code> documentation. Note that for
1374+
properties with a public, nonstatic getter. Eligible setters also
1375+
include public, nonstatic, non- <code>readonly</code> fields. If a class
1376+
has two properties and/or fields of the form "X" and "IsX", where
1377+
"X" is any name, or has multiple properties and/or fields with the
1378+
same name, those properties and fields are ignored.</li> <li>(*) In
1379+
the Java version, eligible setters are public, nonstatic methods
1380+
starting with "set" followed by a character other than a basic digit
1381+
or lower-case letter, that is, other than "a" to "z" or "0" to "9",
1382+
that take one parameter. The class containing an eligible setter
1383+
must have a public, nonstatic method with the same name, but
1384+
starting with "get" or "is" rather than "set", that takes no
1385+
parameters and does not return void. (For example, if a class has
1386+
"public setValue(string)" and "public getValue()", "setValue" is an
1387+
eligible setter. However, "setValue()" and "setValue(string, int)"
1388+
are not eligible setters.) In addition, public, nonstatic, nonfinal
1389+
fields are also eligible setters. If a class has two or more
1390+
otherwise eligible setters (methods and/or fields) with the same
1391+
name, but different parameter type, they are not eligible
1392+
setters.</li> <li>Then, the method creates an object of the given
1393+
type and invokes each eligible setter with the corresponding value
1394+
in the CBOR map, if any. Key names in the map are matched to
1395+
eligible setters according to the rules described in the <code>PODOptions</code> documentation. Note that for
13931396
security reasons, certain types are not supported even if they
1394-
contain eligible setters.</li> </ul> <p>REMARK: A certain
1395-
consistency between .NET and Java and between FromObject and
1396-
ToObject are sought for version 4.0. It is also hoped that the
1397-
ToObject method will support deserializing to objects consisting of
1398-
fields and not getters ("getX()" methods), both in .NET and in
1399-
Java.</p><p> </p><p>Java offers no easy way to express a generic type,
1400-
at least none as easy as C#'s <code>typeof</code> operator. The following
1401-
example, written in Java, is a way to specify that the return value
1402-
will be an ArrayList of string objects.</p> <pre>Type
1403-
arrayListString = new ParameterizedType() { public Type[]
1404-
getActualTypeArguments() { // Contains one type parameter, string
1405-
return new Type[] { string.class }; } public Type getRawType() { /*
1406-
Raw type is ArrayList */ return ArrayList.class; } public Type
1407-
getOwnerType() { return null; } }; ArrayList&lt;string&gt; array =
1408-
(ArrayList&lt;string&gt;)
1397+
contain eligible setters.</li> </ul><p> </p><p>Java offers no easy way
1398+
to express a generic type, at least none as easy as C#'s
1399+
<code>typeof</code> operator. The following example, written in Java, is a
1400+
way to specify that the return value will be an ArrayList of string
1401+
objects.</p> <pre>Type arrayListString = new ParameterizedType() {
1402+
public Type[] getActualTypeArguments() { // Contains one type
1403+
parameter, string return new Type[] { string.class }; } public Type
1404+
getRawType() { /* Raw type is ArrayList */ return ArrayList.class; }
1405+
public Type getOwnerType() { return null; } };
1406+
ArrayList&lt;string&gt; array = (ArrayList&lt;string&gt;)
14091407
cborArray.ToObject(arrayListString);</pre> <p>By comparison, the C#
14101408
version is much shorter.</p> <pre>List&lt;string&gt; array =
14111409
(List&lt;string&gt;)cborArray.ToObject(
@@ -1832,24 +1830,27 @@ Generates a CBORObject from an arbitrary object. See the overload of this
18321830
specially handled above, this method checks the <paramref name='obj'/> parameter for eligible getters as follows:</li> <li>(*)
18331831
In the .NET version, eligible getters are the public, nonstatic
18341832
getters of read/write properties (and also those of read-only
1835-
properties in the case of a compiler-generated type). If a class has
1836-
two properties of the form "X" and "IsX", where "X" is any name, or
1837-
has multiple properties with the same name, those properties are
1833+
properties in the case of a compiler-generated type). Eligible
1834+
getters also include public, nonstatic, non- <code>readonly</code> fields.
1835+
If a class has two properties and/or fields of the form "X" and
1836+
"IsX", where "X" is any name, or has multiple properties and/or
1837+
fields with the same name, those properties and fields are
18381838
ignored.</li> <li>(*) In the Java version, eligible getters are
18391839
public, nonstatic methods starting with "get" or "is" (either word
18401840
followed by a character other than a basic digit or lower-case
18411841
letter, that is, other than "a" to "z" or "0" to "9"), that take no
18421842
parameters and do not return void, except that methods named
1843-
"getClass" are not eligible getters. If a class has two otherwise
1844-
eligible getters of the form "isX" and "getX", where "X" is the same
1845-
in both, or two such getters with the same name but different return
1846-
type, they are not eligible getters.</li> <li>Then, the method
1847-
returns a CBOR map with each eligible getter's name or property name
1848-
as each key, and with the corresponding value returned by that
1849-
getter as that key's value. Before adding a key-value pair to the
1850-
map, the key's name is adjusted according to the rules described in
1851-
the <code>PODOptions</code> documentation. Note that
1852-
for security reasons, certain types are not supported even if they
1843+
"getClass" are not eligible getters. In addition, public, nonstatic,
1844+
nonfinal fields are also eligible getters. If a class has two
1845+
otherwise eligible getters (methods and/or fields) of the form "isX"
1846+
and "getX", where "X" is the same in both, or two such getters with
1847+
the same name but different return type, they are not eligible
1848+
getters.</li> <li>Then, the method returns a CBOR map with each
1849+
eligible getter's name or property name as each key, and with the
1850+
corresponding value returned by that getter as that key's value.
1851+
Before adding a key-value pair to the map, the key's name is
1852+
adjusted according to the rules described in the <code>PODOptions</code> documentation. Note that for
1853+
security reasons, certain types are not supported even if they
18531854
contain eligible getters.</li></ul> <p><b>REMARK:</b>.NET
18541855
enumeration (<code>Enum</code>) constants could also have been converted
18551856
to text strings with <code>toString()</code>, but that method will return
@@ -1859,11 +1860,6 @@ Generates a CBORObject from an arbitrary object. See the overload of this
18591860
text strings, constants from Enum types with the <code>Flags</code>
18601861
attribute, and constants from the same Enum type that share an
18611862
underlying value, should not be passed to this method.</p>
1862-
<p>REMARK: A certain consistency between .NET and Java and between
1863-
FromObject and ToObject are sought for version 4.0. It is also hoped
1864-
that the ToObject method will support deserializing to objects
1865-
consisting of fields and not getters ("getX()" methods), both in
1866-
.NET and in Java.</p>
18671863

18681864
**Parameters:**
18691865

@@ -3201,9 +3197,10 @@ Determines whether a value of the given key exists in this object.
32013197
or is a CBOR map itself, the keys to the map are written out to the
32023198
byte array in an undefined order. The example code given in <see cref='PeterO.Cbor.CBORObject.WriteTo(System.IO.InputStream)'/> can be
32033199
used to write out certain keys of a CBOR map in a given order. For
3204-
the CTAP2 canonical ordering, which is useful for implementing Web
3205-
Authentication, call <code>EncodeToBytes(new CBOREncodeOptions(false,
3206-
false, true))</code> rather than this method.</p>
3200+
the CTAP2 (FIDO Client-to-Authenticator Protocol 2) canonical
3201+
ordering, which is useful for implementing Web Authentication, call
3202+
<code>EncodeToBytes(new CBOREncodeOptions("ctap2canonical=true"))</code>
3203+
rather than this method.</p>
32073204

32083205
**Returns:**
32093206

@@ -3213,10 +3210,11 @@ Determines whether a value of the given key exists in this object.
32133210
public byte[] EncodeToBytes​(CBOREncodeOptions options)
32143211
Writes the binary representation of this CBOR object and returns a byte
32153212
array of that representation, using the specified options for
3216-
encoding the object to CBOR format. For the CTAP2 canonical
3217-
ordering, which is useful for implementing Web Authentication, call
3218-
this method as follows: <code>EncodeToBytes(new
3219-
CBOREncodeOptions(false, false, true))</code>.
3213+
encoding the object to CBOR format. For the CTAP2 (FIDO
3214+
Client-to-Authenticator Protocol 2) canonical ordering, which is
3215+
useful for implementing Web Authentication, call this method as
3216+
follows: <code>EncodeToBytes(new
3217+
CBOREncodeOptions("ctap2canonical=true"))</code>.
32203218

32213219
**Parameters:**
32223220

api/com.upokecenter.cbor.PODOptions.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Options for converting "plain old data" objects (better known as POCOs in
2626
## Methods
2727

2828
* `boolean getUseCamelCase()`<br>
29-
Gets a value indicating whether property names are converted to camel
30-
case before they are used as keys.
29+
Gets a value indicating whether property, field, and method names are
30+
converted to camel case before they are used as keys.
3131
* `java.lang.String toString()`<br>
3232
Gets the values of this options object's properties in text form.
3333

@@ -54,31 +54,35 @@ Gets the values of this options object's properties in text form.
5454

5555
### getUseCamelCase
5656
public final boolean getUseCamelCase()
57-
<p>Gets a value indicating whether property names are converted to camel
58-
case before they are used as keys. This option changes the behavior
59-
of key name serialization as follows. If "useCamelCase" is
60-
<code>false</code> :</p> <ul> <li>In the .NET version, all key names are
61-
capitalized, meaning the first letter in the name is converted to a
62-
basic upper-case letter if it's a basic lower-case letter ("a" to
63-
"z"). (For example, "Name" and "IsName" both remain unchanged.)</li>
64-
<li>In the Java version, for each eligible method name, the word
65-
"get" or "set" is removed from the name if the name starts with that
66-
word, then the name is capitalized. (For example, "getName" and
67-
"setName" both become "Name", and "isName" becomes
68-
"IsName".)</li></ul> <p>If "useCamelCase" is <code>true</code> :</p> <ul>
69-
<li>In the .NET version, for each eligible property name, the word
70-
"Is" is removed from the name if the name starts with that word,
71-
then the name is converted to camel case, meaning the first letter
72-
in the name is converted to a basic lower-case letter if it's a
73-
basic upper-case letter ("A" to "Z"). (For example, "Name" and
74-
"IsName" both become "name".)</li> <li>In the Java version, for each
75-
eligible method name, the word "get", "set", or "is" is removed from
57+
<p>Gets a value indicating whether property, field, and method names are
58+
converted to camel case before they are used as keys. This option
59+
changes the behavior of key name serialization as follows. If
60+
"useCamelCase" is <code>false</code> :</p> <ul> <li>In the .NET version,
61+
all key names are capitalized, meaning the first letter in the name
62+
is converted to a basic upper-case letter if it's a basic lower-case
63+
letter ("a" to "z"). (For example, "Name" and "IsName" both remain
64+
unchanged.)</li> <li>In the Java version, all field names are
65+
capitalized, and for each eligible method name, the word "get" or
66+
"set" is removed from the name if the name starts with that word,
67+
then the name is capitalized. (For example, "getName" and "setName"
68+
both become "Name", and "isName" becomes "IsName".)</li></ul> <p>If
69+
"useCamelCase" is <code>true</code> :</p> <ul> <li>In the .NET version,
70+
for each eligible property or field name, the word "Is" is removed
71+
from the name if the name starts with that word, then the name is
72+
converted to camel case, meaning the first letter in the name is
73+
converted to a basic lower-case letter if it's a basic upper-case
74+
letter ("A" to "Z"). (For example, "Name" and "IsName" both become
75+
"name".)</li> <li>In the Java version: For each eligible method
76+
name, the word "get", "set", or "is" is removed from the name if the
77+
name starts with that word, then the name is converted to camel
78+
case. (For example, "getName", "setName", and "isName" all become
79+
"name".) For each eligible field name, the word "is" is removed from
7680
the name if the name starts with that word, then the name is
77-
converted to camel case. (For example, "getName", "setName", and
78-
"isName" all become "name".)</li></ul> <p>In the description above,
79-
a name "starts with" a word if that word begins the name and is
80-
followed by a character other than a basic digit or basic lower-case
81-
letter, that is, other than "a" to "z" or "0" to "9".</p>
81+
converted to camel case. (For example, "name" and "isName" both
82+
become "name".)</li></ul> <p>In the description above, a name
83+
"starts with" a word if that word begins the name and is followed by
84+
a character other than a basic digit or basic lower-case letter,
85+
that is, other than "a" to "z" or "0" to "9".</p>
8286

8387
**Returns:**
8488

0 commit comments

Comments
 (0)