20
20
from wlsdeploy .logging .platform_logger import PlatformLogger
21
21
import wlsdeploy .exception .exception_helper as exception_helper
22
22
23
+ # Unlike with yaml files, JSON files do not allow comments. remove from file
24
+ COMMENT_MATCH = '# - '
23
25
24
26
class JsonToPython (object ):
25
27
"""
@@ -155,6 +157,7 @@ def _write_dictionary_to_json_file(self, dictionary, writer, indent=''):
155
157
:param writer: where to write the dictionary into json syntax
156
158
:param indent: current string indention of the json syntax. If not provided, indent is an empty string
157
159
"""
160
+ _method_name = '_write_dictionary_to_json_file'
158
161
_start_dict = '{'
159
162
_end_dict = '}'
160
163
@@ -167,15 +170,18 @@ def _write_dictionary_to_json_file(self, dictionary, writer, indent=''):
167
170
168
171
indent += self ._indent_unit
169
172
for key , value in dictionary .iteritems ():
170
- writer .println (end_line )
171
- end_line = ','
172
- writer .write (indent + '"' + _escape_text (key ) + '" : ' )
173
- if isinstance (value , dict ):
174
- self ._write_dictionary_to_json_file (value , writer , indent )
175
- elif isinstance (value , list ):
176
- self ._write_list_to_json_file (value , writer , indent )
173
+ if isinstance (key , basestring ) and key .startswith (COMMENT_MATCH ):
174
+ self ._logger .finer ('WLSDPLY-01714' , key , class_name = self ._class_name , method_name = _method_name )
177
175
else :
178
- writer .write (_format_json_value (value ))
176
+ writer .println (end_line )
177
+ end_line = ','
178
+ writer .write (indent + '"' + _escape_text (key ) + '" : ' )
179
+ if isinstance (value , dict ):
180
+ self ._write_dictionary_to_json_file (value , writer , indent )
181
+ elif isinstance (value , list ):
182
+ self ._write_list_to_json_file (value , writer , indent )
183
+ else :
184
+ writer .write (_format_json_value (value ))
179
185
writer .println ()
180
186
writer .write (end_indent + _end_dict )
181
187
0 commit comments