1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include "json_exporter.h" 16 17 #include <meta/api/util.h> 18 19 #include "backend/json_output.h" 20 21 META_BEGIN_NAMESPACE() 22 namespace Serialization { 23 Export(CORE_NS::IFile & output,const IObject::ConstPtr & object)24ReturnError JsonExporter::Export(CORE_NS::IFile& output, const IObject::ConstPtr& object) 25 { 26 Exporter exp; 27 auto tree = exp.Export(object); 28 if (!tree) { 29 return GenericError::FAIL; 30 } 31 JsonOutput backend; 32 auto json = backend.Process(tree); 33 if (json.empty()) { 34 return GenericError::FAIL; 35 } 36 output.Write(json.c_str(), json.size()); 37 return GenericError::SUCCESS; 38 } 39 40 } // namespace Serialization 41 META_END_NAMESPACE() 42