Conditions | 1 |
Paths | 2 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | var Slf4j = require('@ama-team/voxengine-sdk').Logger.Slf4j |
||
9 | factory: function (options) { |
||
10 | var name = 'ama-team.vsf.schema.defaults.deserializer' |
||
11 | var logger = Slf4j.factory(options, name) |
||
12 | return function (input) { |
||
13 | if (!input || input === '') { |
||
14 | logger.debug('Provided input is a falsey value, returning empty object') |
||
15 | return {} |
||
16 | } |
||
17 | if (typeof input !== 'string') { |
||
18 | logger.debug('Provided input is not a string, returning object with ' + |
||
19 | 'input as $.customData') |
||
20 | return {customData: input} |
||
21 | } |
||
22 | try { |
||
23 | return JSON.parse(input) |
||
24 | } catch (e) { |
||
25 | logger.warn('Failed to deserialize JSON from {}, returning object ' + |
||
26 | 'with input as $.customData', input) |
||
27 | return {customData: input} |
||
28 | } |
||
29 | } |
||
30 | } |
||
31 | } |
||
32 |