Nya::Serializable
Constants
Class methods
Parses decimal, binary, octal or hexadecimal number into a specified integer class.
Accepts numbers like 123 (decimal), 0123 (octal), 0xDEADBEEF (hex),
0b10010000 (binary)
Instance methods
Macros
A macro to declare serializable attributes
In contrast to serializable macro, which declares child nodes,
this macro is used to declare XML attributes, so a declared
attribute must be a String, Bool, Enum, or have a constructor
from String (like floating point or integer values)
So, an example like this
class Foo
include Nya::Serializable
property foo = "bar", bar = SomeEnum::Value
attribute foo : String, bar : SomeEnum
# ... other props here
end
Will give a following output:
<Foo foo="bar", bar="Value">
... other props here ...
</Foo>
NOTE: Notice the property macro calls in the class declaration. Like
the serializable macro, attribute also calls property accessors.
WARNING: As with serializable, serializable class must have a default
constructor, so properties must have a default value
A macro to declare serializable properties
Must be called with TypeDeclarations, for example:
serializable foo : String, bar : Array(String), baz : Another::Serializable
serializable foobar : Array(Another::Serializable)
The above example will be serialized to XML like following:
...
<foo>Foo content</foo>
<bar>
<item>Bar 1</item>
<item>Bar 2</item>
...
</bar>
<baz>
<Another:Serializable>
...
</Another:Serializable>
</baz>
<foobar>
<Another:Serializable>
...
</Another:Serializable>
</foobar>
...
NOTE: To serialize or deserialize a property, an object should have property
accessor methods, generated with a property macro call or manually written.
WARNING: Serializable class must have a default constructor, so properties must have a default value
Translates Crystal type name into XML compatible tag name
Converts first part of a Fully::Qualified::Name into a XML namespace
and joins the rest with underscores, like Fully:Qualified_Name.
Converts generic type names like Generic(A, B) into Generic..A.B-.
WARNING: This macro is intended for internal use, generic type conversion is currently not used in the library and may be removed in future.
NOTE: Type must be a StringLiteral, Generic, Path, or just an
unqualified MacroId. In the latter case, type name is just stringified
without any conversion.