Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an Swift Codable export with default value supported #143

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d6f592d
Merge pull request #88 from AlexxNica/patch-1
Ahmed-Ali Nov 15, 2017
bf8134e
Merge pull request #96 from kashifshaikh/master
Ahmed-Ali Nov 15, 2017
16893c7
Merge pull request #93 from narlei/master
Ahmed-Ali Nov 15, 2017
c5a4da4
fix a complier error in SwiftyJSON - Class
superk589 Nov 27, 2017
779a06f
Migrate to Swift 4
serhii-londar Dec 13, 2017
e40b258
Added Swift-Codable-Struct with forced unwrapped option
mumer92 Dec 26, 2017
2f8ba42
added back credit file
mumer92 Dec 26, 2017
df54d97
Change generic type from 'AnyObject' to 'String' -> Fixes #105
Feb 12, 2018
8528d6a
Java Gson for Android: Fix method name to be "optString" instead of "…
Mar 3, 2018
02a96ed
Fix: float type issue
Mar 3, 2018
4c61a93
Update to Swift 4.2
BrychanOdlum Oct 2, 2018
0a3d17f
Updating GHANGELOG.md for release 1.0.9
Ahmed-Ali Nov 24, 2018
cdd8a4f
Merge branch 'master' of git://github.com/superk589/JSONExport into s…
Ahmed-Ali Nov 24, 2018
3b306da
Merge branch 'superk589-master' into develop
Ahmed-Ali Nov 24, 2018
30d8785
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
8e804f6
Merge branch 'master' of git://github.com/serhii-londar/JSONExport in…
Ahmed-Ali Nov 24, 2018
8069c92
Merge branch 'serhii-londar-master'
Ahmed-Ali Nov 24, 2018
a45d1ae
Merge branch 'serhii-londar-master' into develop
Ahmed-Ali Nov 24, 2018
c20cabb
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
2c3864f
Merge branch 'master' of git://github.com/mumer92/JSONExport into mum…
Ahmed-Ali Nov 24, 2018
330d94b
Merge branch 'mumer92-master' into develop
Ahmed-Ali Nov 24, 2018
9ca6bdc
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
a9b4ca0
Merge branch 'fix_generic_type_swift_struct_codable' of git://github.…
Ahmed-Ali Nov 24, 2018
870ee94
Merge branch 'ankushkushwaha-fix_generic_type_swift_struct_codable' i…
Ahmed-Ali Nov 24, 2018
0c5bd0d
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
790b7fb
Merge branch 'feature/fix_java_gson_for_android' of git://github.com/…
Ahmed-Ali Nov 24, 2018
96d1f27
Merge branch 'ty0521-fss-feature/fix_java_gson_for_android' into develop
Ahmed-Ali Nov 24, 2018
1e806c9
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
a0a7c7e
Merge branch 'master' of git://github.com/BrychanOdlum/JSONExport int…
Ahmed-Ali Nov 24, 2018
101a4e9
Merge branch 'BrychanOdlum-master' into develop
Ahmed-Ali Nov 24, 2018
87f71cb
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
a507ecf
Fixing the project file
Ahmed-Ali Nov 24, 2018
db500f5
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
47a897e
Adding Outlaw JSON file to the project as the merge conflicts caused …
Ahmed-Ali Nov 24, 2018
a0ec494
nit: removing empty line
Ahmed-Ali Nov 24, 2018
50e3f93
Fixed an issue with trying to figure the selected language from an UI…
Ahmed-Ali Nov 24, 2018
fe313c0
fixed: update the color under Dark Mode
Sep 6, 2019
ec2051d
Merge pull request #136 from hzb/master
huabin Sep 8, 2019
8fe2606
add codable with default
Jul 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,3 +5,34 @@ JSONExport.xcodeproj/xcuserdata/ahmed.xcuserdatad/xcdebugger/Breakpoints_v2.xcbk
JSONExport.xcodeproj/project.xcworkspace/xcuserdata/ahmedali.xcuserdatad/UserInterfaceState.xcuserstate
JSONExport.xcodeproj/xcuserdata/ahmedali.xcuserdatad/xcschemes/JSONExport.xcscheme
JSONExport.xcodeproj/xcuserdata/ahmedali.xcuserdatad/xcschemes/xcschememanagement.plist


# OS X Finder
.DS_Store
.LSOverride

# Xcode per-user config
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
#*.xcworkspace
xcuserdata


# Build products
build/
*.o
*.LinkFileList
*.hmap

# Automatic backup files
*~.nib/
*.swp
*~
*.dat
*.dep

Breakpoints.xcbkptlist
35 changes: 34 additions & 1 deletion JSONExport/FileRepresenter.swift
Original file line number Diff line number Diff line change
@@ -372,7 +372,18 @@ class FileRepresenter{
if let index = lang.basicTypesWithSpecialFetchingNeeds.index(of: property.type), let replacement = lang.basicTypesWithSpecialFetchingNeedsReplacements?[index]{
propertyHandlingStr = propertyHandlingStr.replacingOccurrences(of: varTypeReplacement, with: replacement)


var castString = String()
if let cast = lang.basicTypesWithSpecialFetchingNeedsTypeCast?[index]{
// if needs cast
if !cast.isEmpty {
castString = "(\(cast)) "
}
else {
castString = cast
}
}
propertyHandlingStr = propertyHandlingStr.replacingOccurrences(of: varTypeCast, with: castString)

let lowerCaseType = property.type.lowercased()
propertyHandlingStr = propertyHandlingStr.replacingOccurrences(of: lowerCaseVarType, with: lowerCaseType)

@@ -468,6 +479,16 @@ class FileRepresenter{
propertyStr = constructor.fetchArrayOfBasicTypePropertyFromMap
let replacement = lang.basicTypesWithSpecialFetchingNeedsReplacements[index]
propertyStr = propertyStr.replacingOccurrences(of: varTypeReplacement, with: replacement)

// if needs cast
let cast = lang.basicTypesWithSpecialFetchingNeedsTypeCast[index]
if !cast.isEmpty {
propertyStr = propertyStr.replacingOccurrences(of: varTypeCast, with: "(\(cast)) ")
}
else {
propertyStr = propertyStr.replacingOccurrences(of: varTypeCast, with: cast)
}

}else{
propertyStr = constructor.fetchBasicTypePropertyFromMap
}
@@ -500,6 +521,18 @@ class FileRepresenter{
propertyStr = propertyStr.replacingOccurrences(of: varTypeReplacement, with: replacement)
}

var castString = String()
if let cast = lang.basicTypesWithSpecialFetchingNeedsTypeCast?[index!]{
// if needs cast
if !cast.isEmpty {
castString = "(\(cast)) "
}
else {
castString = cast
}
}
propertyStr = propertyStr.replacingOccurrences(of: varTypeCast, with: castString)

let lowerCaseType = property.type.lowercased()
propertyStr = propertyStr.replacingOccurrences(of: lowerCaseVarType, with: lowerCaseType)

2 changes: 2 additions & 0 deletions JSONExport/LangModel.swift
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ class LangModel{
var arrayType : String!
var basicTypesWithSpecialFetchingNeeds : [String]!
var basicTypesWithSpecialFetchingNeedsReplacements : [String]!
var basicTypesWithSpecialFetchingNeedsTypeCast : [String]!
var basicTypesWithSpecialStoringNeeds : [String]!
var booleanGetter : String!
var briefDescription : String!
@@ -50,6 +51,7 @@ class LangModel{
arrayType = dictionary["arrayType"] as? String
basicTypesWithSpecialFetchingNeeds = dictionary["basicTypesWithSpecialFetchingNeeds"] as? [String]
basicTypesWithSpecialFetchingNeedsReplacements = dictionary["basicTypesWithSpecialFetchingNeedsReplacements"] as? [String]
basicTypesWithSpecialFetchingNeedsTypeCast = dictionary["basicTypesWithSpecialFetchingNeedsTypeCast"] as? [String]
basicTypesWithSpecialStoringNeeds = dictionary["basicTypesWithSpecialStoringNeeds"] as? [String]
booleanGetter = dictionary["booleanGetter"] as? String
briefDescription = dictionary["briefDescription"] as? String
1 change: 1 addition & 0 deletions JSONExport/SharedConstants.swift
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ let varName = "<!VarName!>"
let capitalizedVarName = "<!CapitalizedVarName!>"
let varType = "<!VarType!>"
let varTypeReplacement = "<!VarBasicTypeReplacement!>"
let varTypeCast = "<!VarBasicTypeCast!>"
let capitalizedVarType = "<!CapitalizedVarType!>"
let lowerCaseVarType = "<!LowerCaseVarType!>"
let lowerCaseModelName = "<!LowerCaseModelName!>"
17 changes: 12 additions & 5 deletions JSONExport/Supported Languages/Java-Android Gson.json
Original file line number Diff line number Diff line change
@@ -33,11 +33,18 @@
],
"basicTypesWithSpecialFetchingNeeds" : [
"Object",
"String"
"String",
"float"
],
"basicTypesWithSpecialFetchingNeedsReplacements" : [

"",""
"",
"String",
"Double"
],
"basicTypesWithSpecialFetchingNeedsTypeCast" : [
"",
"",
"float"
],
"constructors": [
{
@@ -47,7 +54,7 @@
"bodyEnd": "\t}\n",
"fetchBasicTypePropertyFromMap": "\t\t<!VarName!> = jsonObject.opt<!CapitalizedVarType!>(\"<!JsonKeyName!>\");\n",
"fetchArrayOfBasicTypePropertyFromMap" : "\t\tJSONArray <!VarName!>Tmp = jsonObject.optJSONArray(\"<!JsonKeyName!>\");\n\t\tif(<!VarName!>Tmp != null){\n\t\t\t<!VarName!> = new <!ElementType!>[<!VarName!>Tmp.length()];\n\t\t\tfor(int i = 0; i < <!VarName!>Tmp.length(); i++){\n\t\t\t\t<!VarName!>[i] = <!VarName!>Tmp.get(i);\n\t\t\t}\n\t\t}\n",
"fetchBasicTypeWithSpecialNeedsPropertyFromMap": "\t\t<!VarName!> = jsonObject.opt<!VarBasicTypeReplacement!>(\"<!JsonKeyName!>\");\n",
"fetchBasicTypeWithSpecialNeedsPropertyFromMap": "\t\t<!VarName!> = <!VarBasicTypeCast!>jsonObject.opt<!VarBasicTypeReplacement!>(\"<!JsonKeyName!>\");\n",
"fetchCustomTypePropertyFromMap": "\t\t<!VarName!> = new <!VarType!>(jsonObject.optJSONObject(\"<!JsonKeyName!>\"));\n",
"fetchArrayOfCustomTypePropertyFromMap": "\t\tJSONArray <!VarName!>JsonArray = jsonObject.optJSONArray(\"<!JsonKeyName!>\");\n\t\tif(<!VarName!>JsonArray != null){\n\t\t\tArrayList<<!ElementType!>> <!VarName!>ArrayList = new ArrayList<>();\n\t\t\tfor (int i = 0; i < <!VarName!>JsonArray.length(); i++) {\n\t\t\t\tJSONObject <!VarName!>Object = <!VarName!>JsonArray.optJSONObject(i);\n\t\t\t\t<!VarName!>ArrayList.add(new <!ElementType!>(<!VarName!>Object));\n\t\t\t}\n\t\t\t<!VarName!> = (<!ElementType!>[]) <!VarName!>ArrayList.toArray();\n\t\t}"
}
@@ -66,4 +73,4 @@
"returnStatement": "\t\t} catch (JSONException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\t\treturn jsonObject;\n"
}
]
}
}