Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
ca9fd2f5
Commit
ca9fd2f5
authored
Mar 12, 2015
by
Harish Butani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add helpers for trait ser/de
parent
767611af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
3 deletions
+41
-3
Serialization.scala
...pache/hadoop/metadata/typesystem/json/Serialization.scala
+15
-1
SerializationJavaTest.java
...adoop/metadata/typesystem/json/SerializationJavaTest.java
+26
-2
No files found.
typesystem/src/main/scala/org/apache/hadoop/metadata/typesystem/json/Serialization.scala
View file @
ca9fd2f5
...
...
@@ -19,7 +19,7 @@
package
org.apache.hadoop.metadata.typesystem.json
import
org.apache.hadoop.metadata.typesystem._
import
org.apache.hadoop.metadata.typesystem.persistence.
{
Id
,
ReferenceableInstance
}
import
org.apache.hadoop.metadata.typesystem.persistence.
{
StructInstance
,
Id
,
ReferenceableInstance
}
import
org.apache.hadoop.metadata.typesystem.types.DataTypes.
{
ArrayType
,
MapType
,
TypeCategory
}
import
org.apache.hadoop.metadata.typesystem.types._
import
org.json4s.JsonAST.JInt
...
...
@@ -271,6 +271,13 @@ object Serialization {
write
(
value
)
}
def
toJson
(
value
:
ITypedInstance
)
:
String
=
{
implicit
val
formats
=
org
.
json4s
.
native
.
Serialization
.
formats
(
NoTypeHints
)
+
new
TypedStructSerializer
+
new
TypedReferenceableInstanceSerializer
+
new
BigDecimalSerializer
+
new
BigIntegerSerializer
write
(
value
)
}
def
toJsonPretty
(
value
:
ITypedReferenceableInstance
)
:
String
=
{
implicit
val
formats
=
org
.
json4s
.
native
.
Serialization
.
formats
(
NoTypeHints
)
+
new
TypedStructSerializer
+
new
TypedReferenceableInstanceSerializer
+
new
BigDecimalSerializer
+
new
BigIntegerSerializer
...
...
@@ -284,4 +291,11 @@ object Serialization {
read
[
ReferenceableInstance
](
jsonStr
)
}
def
traitFromJson
(
jsonStr
:
String
)
:
ITypedInstance
=
{
implicit
val
formats
=
org
.
json4s
.
native
.
Serialization
.
formats
(
NoTypeHints
)
+
new
TypedStructSerializer
+
new
TypedReferenceableInstanceSerializer
+
new
BigDecimalSerializer
+
new
BigIntegerSerializer
read
[
StructInstance
](
jsonStr
)
}
}
typesystem/src/test/java/org/apache/hadoop/metadata/typesystem/json/SerializationJavaTest.java
View file @
ca9fd2f5
...
...
@@ -21,8 +21,7 @@ package org.apache.hadoop.metadata.typesystem.json;
import
com.google.common.collect.ImmutableList
;
import
org.apache.hadoop.metadata.BaseTest
;
import
org.apache.hadoop.metadata.MetadataException
;
import
org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.typesystem.Referenceable
;
import
org.apache.hadoop.metadata.typesystem.*
;
import
org.apache.hadoop.metadata.typesystem.types.AttributeDefinition
;
import
org.apache.hadoop.metadata.typesystem.types.ClassType
;
import
org.apache.hadoop.metadata.typesystem.types.DataTypes
;
...
...
@@ -148,4 +147,28 @@ public class SerializationJavaTest extends BaseTest {
Assert
.
assertEquals
(
hrDept2
.
toString
(),
hrDeptStr
);
}
@Test
public
void
testTrait
()
throws
MetadataException
{
TypeSystem
ts
=
getTypeSystem
();
HierarchicalTypeDefinition
<
TraitType
>
securityClearanceTypeDef
=
createTraitTypeDef
(
"SecurityClearance2"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"level"
,
DataTypes
.
INT_TYPE
)
);
ts
.
defineTypes
(
ImmutableList
.<
StructTypeDefinition
>
of
(),
ImmutableList
.<
HierarchicalTypeDefinition
<
TraitType
>>
of
(
securityClearanceTypeDef
),
ImmutableList
.<
HierarchicalTypeDefinition
<
ClassType
>>
of
());
Struct
s
=
new
Struct
(
"SecurityClearance2"
);
s
.
set
(
"level"
,
1
);
TraitType
tType
=
ts
.
getDataType
(
TraitType
.
class
,
"SecurityClearance2"
);
ITypedInstance
t
=
tType
.
convert
(
s
,
Multiplicity
.
REQUIRED
);
String
jsonStr
=
Serialization
$
.
MODULE
$
.
toJson
(
t
);
ITypedInstance
t2
=
Serialization
$
.
MODULE
$
.
traitFromJson
(
jsonStr
);
Assert
.
assertEquals
(
t
.
toString
(),
t2
.
toString
());
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment