1
+ /**
2
+ * Copyright 2016 InscopeMetrics, Inc
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
package com .arpnetworking .configuration .jackson .akka ;
2
17
3
18
import akka .actor .Props ;
4
19
import com .arpnetworking .commons .builder .Builder ;
5
20
import com .fasterxml .jackson .core .JsonParser ;
6
- import com .fasterxml .jackson .core .JsonProcessingException ;
7
21
import com .fasterxml .jackson .core .TreeNode ;
8
22
import com .fasterxml .jackson .databind .DeserializationContext ;
9
23
import com .fasterxml .jackson .databind .JsonDeserializer ;
14
28
import java .io .IOException ;
15
29
16
30
/**
17
- * Deserializer that will create an ActorBuilder for the given actor, then create the Actor from Guice
31
+ * Deserializer that will create an ActorBuilder for the given actor, then create a Props from Guice.
32
+ *
18
33
* @author Brandon Arp (brandon dot arp at inscopemetrics dot com)
19
34
*/
20
35
public class ActorBuilderDeserializer extends JsonDeserializer <Props > {
@@ -28,15 +43,15 @@ public ActorBuilderDeserializer(final ObjectMapper mapper) {
28
43
}
29
44
30
45
@ Override
31
- public Props deserialize (final JsonParser p , final DeserializationContext ctxt ) throws IOException , JsonProcessingException {
46
+ public Props deserialize (final JsonParser p , final DeserializationContext ctxt ) throws IOException {
32
47
final TreeNode treeNode = p .readValueAsTree ();
33
48
final String type = ((TextNode ) treeNode .get ("type" )).textValue ();
34
49
try {
35
50
final Class <?> clazz = Class .forName (type );
36
51
final Class <? extends Builder <? extends Props >> builder = getBuilderForClass (clazz );
37
52
final Builder <? extends Props > value = _mapper .readValue (treeNode .toString (), builder );
38
53
return value .build ();
39
- } catch (ClassNotFoundException e ) {
54
+ } catch (final ClassNotFoundException e ) {
40
55
throw new JsonMappingException (p , String .format ("Unable to find class %s referenced by Props type" , type ));
41
56
}
42
57
}
0 commit comments